CakePHP加载默认控制器

时间:2014-11-06 07:44:41

标签: cakephp

我想为网站编写控制器,模型和视图。我写了它,并将它添加到routes.php,但它加载了根路径(内容控制器)。它不显示任何错误,只是重定向到根。我使用了CakePHP的1.1.16.5421版本。

这是我的routes.php:

$Route->connect('/', array('controller' => 'contents'));
$Route->connect('/services', array('controller' => 'contents', 'action' => 'services'));
$Route->connect('/kapcsolat', array('controller' => 'contents', 'action' => 'contact_us'));
$Route->connect('/rolunk', array('controller' => 'contents', 'action' => 'about'));
$Route->connect('/privacy-notes', array('controller' => 'contents', 'action' => 'show', 1));
$Route->connect('/conditions-of-use', array('controller' => 'contents', 'action' => 'show', 2));
$Route->connect('/vasarlasi_folyamat', array('controller' => 'contents', 'action' => 'show', 3));


$Route->connect('/login', array('controller' => 'users', 'action' => 'login'));
$Route->connect('/logout', array('controller' => 'users', 'action' => 'logout'));
$Route->connect('/register', array('controller' => 'users', 'action' => 'register'));
$Route->connect('/my_account', array('controller' => 'users', 'action' => 'my_account'));

$Route->connect('/products/special', array('controller' => 'products', 'action' => 'show_special'));
$Route->connect('/products/new', array('controller' => 'products', 'action' => 'show_new'));

$Route->connect('/advanced_search', array('controller' => 'products', 'action' => 'advanced_search'));

$Route->connect('/gallery', array('controller' => 'contents', 'action' => 'show', 14));

$Route->connect('/gallery', array('controller' => 'contents', 'action' => 'show', 14));
$Route->connect('/ajandek', array('controller' => 'ajandek', 'action' => 'toXML'));

这是我的控制者:

class AjandekController extends AppController{
    var $name = 'ajandek';
    var $helpers = array('Html');
    var $uses = array('ajandek');
    public function beforeFilter() {
        parent::beforeFilter();
    }
    public function toXML($id=null){
        if ($id){
            $this->loadModel('AjandekModel');
            $this->set('ajandek', $this->AjandekModel->byID($id));
        }
    }
}

模特:

class AjandekModel extends AppModel{
    var $name="products";
    public function byID($id=null){
        if ($id){
            return $this->findAll(array(
                'id'=>$id
            );
        }
    }
}

以下是我的观点:

<?xml version="1.0" encoding="UTF-8"?> 
<products>
    <?php
        foreach ($content as $item){
            ?>
                <product>
                        <product_id><?php echo $item['ajandek']['id']; ?></product_id>
                        <name><![CDATA[]]></name>
                        <redirect_url><![CDATA[]]></redirect_url>
                        <image_url><?php echo $item['ajandek']['image']; ?></image_url>
                        <image_url_2></image_url_2>
                        <image_url_3></image_url_3>
                        <price><?php echo $item['ajandek']['price']; ?></price>
                        <old_price></old_price>
                        <discount_percent></discount_percent>
                        <description><![CDATA[]]></description>
                <category_id></category_id>
                <product_tags>
                        <ferfi></ferfi>
                        <no></no>
                        <gyerek></gyerek>
                        <felnott></felnott>
                        <idos></idos>
                        </product_tags>
                </product>
            <?php
        }
    ?>
</products>

我希望有人可以帮助我解决它。 :(

0 个答案:

没有答案