如果事件为空,如何阻止访问URL?

时间:2017-12-25 11:03:43

标签: php joomla

如果未设置ohanah_event_id,我需要阻止访问此文件。 我怎么能做到这一点?

<?php

/**
 * @package     Ohanah
 * @copyright   Copyright (C) 2012 - 2016 Beyounic SA. All rights reserved.
 * @license     GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link        http://www.beyounic.com
 */

class ComOhanahViewTicketHtml extends ComOhanahViewHtml
{
    protected function _fetchData(KViewContext $context)
    {
        parent::_fetchData($context);

        if ($context->data->ticket->ohanah_event_id) {
            $doc = JFactory::getDocument();
            $translator = $this->getObject('translator');

            $doc->setTitle($translator->translate('COM_OHANAH_TICKET') . ' - ' . $context->data->ticket->event->title);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
<?php
class ComOhanahViewTicketHtml extends ComOhanahViewHtml
{
    protected function _fetchData(KViewContext $context)
    {
        parent::_fetchData($context);
        if(!empty($context->data->ticket->ohanah_event_id)){
        $context->data->ticket->ohanah_event_id;
            $doc = JFactory::getDocument();
            $translator = $this->getObject('translator');

            $doc->setTitle($translator->translate('COM_OHANAH_TICKET') . ' - ' . $context->data->ticket->event->title);
        }
        else {
       return false;}
    }
}
?>
&#13;
&#13;
&#13;

你可以尝试使用条件和!空,如果它是空的,则返回false给函数