1

I am working on a cms based Yii application. I have recently finished the pages of the backend and can now get the pages from a database.

The trouble begins with getting the requested url and rendering the dynamic layout.

What is the best way to go about this? Like use a start site/domain controller and how do I set it up?

The Rendering with CMenu goes well in the template. The menu shows in the frontend. Here is an example of the menu links I currently use like /home and /company/products. It uses clean urls.

<ul id="yw0">

<li class="active"><a href="/home">Home</a></li>
<li><a href="/about_us">About us</a></li>
<li><a href="/company">Company</a></li>

    <ul>
        <li><a href="/company/products">Products</a></li>
        <li><a href="/company/services">Services</a></li>
    </ul>

<li><a href="/contact">Contact</a></li>

</ul>

But this is one point ahead. The layout needs to be dynamically loaded from a specific page in the backend. Every page can have a different layout. There is a column for this in the database. So for example the url: "http://example.com/home" needs to load 'protected/views/layouts/main.php'

At the moment the links like: "http://example.com/company/products" don't go anywhere. This is obvious because the links don't exist and are dynamically created.

I am thinking I need to do two things:

  • One make a startController that every request goes to and that will handle the loading of the pages and layout.
  • And two some setup with clean Urls.?

That's it.

I can imagine it being not much work. But it's giving me headaches.

Especially the clean urls. They have always been abit confusing to me.

index.php?r=site/index would go to siteController and action index.

But this is not what I want. I also tried setting up the 'urlManager' but it goes to a controller and an action. Like page/default/view/id/. But I don't want to go to an action but just the start controller loading the (next) requested page(with different layout) from the database.

Do I need to setup clean urls somewhere in the config file main.php

Hope it's easy to understand what I like to achieve. Any help is greatly appreciated.

asteri
  • 11,402
  • 13
  • 60
  • 84
Minahalmon
  • 131
  • 2
  • 11

1 Answers1

1

You can set the layout in the controller or also can set the different layout in the each action of a single controller like this.

public function actionActionname()
{
    $this->layout = 'front_layout';
    //Do the actions
    $this->render('renderVariable');
}

And To the full controller layout you can set like this:

class ControllerName extends Controller
{
    public $layout = '//layout path';
Sudhanshu Saxena
  • 1,199
  • 12
  • 32
  • Thanks for your reply. The thing is setting the layout with code in the controller is not really dynamic. But the main problem is how do I make a start controller. A entry controller. And the clean urls. I have tried url manager again. And it now goes to: yiitest/frontend/index.php/home . As you can see it uses the home url from the database. But I get error404 Unable to resolve the request "home". But how and where do I set up an entry controller. SiteController and pageController in "protected/controllers/" do not get called. Edit: sorry first time using stackoverflow – Minahalmon Mar 07 '13 at 11:14