Jonathon Posted December 23, 2011 Share Posted December 23, 2011 Hi Larry, I have a personal project I've been meaning to do for a while, it will be quite big and I imagine fairly complex as there's a lot of things I want it to be able to do. I also have been meaning to get more into Yii, so i thought why not build this personal project in Yii! Especially as frameworks can help you accomplish fairly time consuming tasks quickly and a lot of security / validation concerns are often put to rest within the framework itself. I started building together the HTML and CSS I was going to use for this project, I'm about 75% through the home page before I decided to combine this with Yii, but I wondered if you had any guidance or tips really in how to get Yii to behave visually the way you want it to? Can you make it generate HTML Ids or classes or does it always have a series of its own tags? Obviously most websites have 3+ different style layouts, the index is usually different from the bulk of content, which is different from search results which is different from a contact page etc. For instance my index page I wanted a fairly big search ability, with lots of options but on a more standard page this big search ability wouldn't need to be there at all, as the site always runs through index.php I wasn't sure how Yii would know to show this search capability on index and not on a standard page for one and that's before I even go about styling it. Hope this makes sense? Link to comment Share on other sites More sharing options...
Jonathon Posted December 26, 2011 Author Share Posted December 26, 2011 I think I may have worked out how it fits together more now. Great series on Yii though Larry, can't wait for the Yii book. Link to comment Share on other sites More sharing options...
Larry Posted December 27, 2011 Share Posted December 27, 2011 Hey Jonathon. Apologies for not replying before, busy with the holidays and all. As for using Yii with the HTML and CSS, mostly you'll want to create separate layout files for the X number of unique layouts. Other than that, try to make your view files as specific as possible. The views can create the IDs and classes as needed, just as you would in straight PHP. Link to comment Share on other sites More sharing options...
Jonathon Posted December 27, 2011 Author Share Posted December 27, 2011 (edited) <p>No problem Larry, you are a busy man at the best of times so this period undoubtedly makes you more busy. Yeah I'd been reading the Yii docs and more importantly the forum about these things and definately understand how the HTML and CSS fit together better for it. But, could you help clear something up for me though, I get the bootstrap approach, but how do you define that 1 page should have layout X and another page have layout Y?In the view file inside 'layouts/'? Looking at my main.php I have the menu bar and start the html content tag. Then I seem to get index.php view included and the column1.php which I've adjusted so my index page is coming together visually, but when I come to another page that needs a different style say column2.php for instance how do I allow for that change, within the SiteController.php? I did have a play with that but didn't seem to get it to work. Edited December 28, 2011 by Jonathon Link to comment Share on other sites More sharing options...
Jonathon Posted December 28, 2011 Author Share Posted December 28, 2011 (edited) I think i've figured it out: <?php $this->layout='column2'; ?> inside the actual view of that page Which has lead me to another question inside a file like contact.php when I try to use the above code to set the layout it fails, do I need to do that inside the site controller? and how do I set the default layout of the site? For instance my index page pulls the view index.php in and also column1.php in which is ok I guess for the moment as i've altered the views to make my home page. But when I come to a page like Contact.php that i am having a slight layout issue with a more generic style may be best to use as the default layout of the site and make index a special case. Edited December 28, 2011 by Jonathon Link to comment Share on other sites More sharing options...
Jonathon Posted December 28, 2011 Author Share Posted December 28, 2011 I have altered my Controller.php inside components to class Controller extends CController { /** * @var string the default layout for the controller view. Defaults to '//layouts/column1', * meaning using a single column layout. See 'protected/views/layouts/column1.php'. */ public $layout='//layouts/standard'; /** * @var array context menu items. This property will be assigned to {@link CMenu::items}. */ public $menu=array(); /** * @var array the breadcrumbs of the current page. The value of this property will * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links} * for more details on how to specify this property. */ public $breadcrumbs=array(); } This now puts my contact page and about to the default layout of standard by then adding <?php $this->layout='column1'; ?> to my index page my index page is keeping the style i wanted for it, but at the same time allowing the rest of my site to take the more standard style. So I think I may have solved this? But a question for me does remain in why I can't change the contact.php layout using $this->layout='whatever'; is this because it's a widget? Link to comment Share on other sites More sharing options...
Larry Posted January 3, 2012 Share Posted January 3, 2012 Jonathon, is this still unresolved for you? It seems to overlap the other thread. Link to comment Share on other sites More sharing options...
Jonathon Posted January 3, 2012 Author Share Posted January 3, 2012 Yes thanks Larry this is resolved. They started out as two separate threads but my lack on yii knowledge meant it was really just one very related thread - Thanks for your help. Link to comment Share on other sites More sharing options...
Recommended Posts