CodeIgniter - big site best practices - codeigniter

CodeIgniter + Template howto design a portal like behavior.
I'm not getting the concept of how to design bigger sites with CodeIgniter and Templates.
The templates I'm using is Template Library for CodeIgniter. I'm having problems solving the following.
What I can see I need is some MasterTemplate that provides "MainRegion" for ProductCatalogue browsing and Account management etc. Then I would like to have a concept of "Widgets" loaded from the MasterTemplate that the user does not interact directly with instead it is simply informative. Ex: ShoppingCartWidget, TopNews etc...
Example of problems:
A) Widget - A shopping cart widget exposes a minimalistic resume of what user has added when browsing the the product catalog in the "MainRegion".
B) Hierachival view structure - When navigating to the "Account section" of the site the site renders a sub-view of the account system in the "MainRegion". My problem is that the state of the AccountSection is lost when I for example leave the "AccountSection" in to "ProductCatalogue" and the back to "Accountsection". I want to be able to render each subsection independtly smothly insterted into the "MainRegion" in the master template.
I really don't get the architecture. I need help to bring real modularity into the design.
I would like to achive the following:
1) View fragments should render from a its own model. Ex: ShoppingCartWidget always reads its state from ShoppingCartModel.
3) View fragments should have a display[on/off] in some MasterTemplate concept. So that I can Ex: Start showing the ShoppingCartWidget when there is something in the ShoppingCart. (I don't want to render '').
4) Stateful views. Ex: UserLoggedIn/UserNotLoggedIn
I'm missing the complex design principles for bigger sites or best practices for CI.
Very greatful for any help!
Thanks
Niclas

HMVC for Codeigniter does what you want: https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home

Related

best way to handle complex page layout in joomla

I have to convert a static site for a client and it has to retain the exisiting layout.
Fortunately, most of the pages don't have to be editable, so for those I was going to use more or less the existing html.
The challenge I am having is that for many of the pages that do need to be editable, the content is laid out in columns (2, 3 and sometimes mixed)
This ( http://globalstrategies.org/index.php/give/hope-partners ) is an example of a page like that, and you can see others on the site where the layout is relatively complex.
I had thought of creating a jce stylesheet that would at least layout the page in the editor in a reasonable way (a bit like a responsive site, by having the columns stacked one after the other) , but I am concerned that my client may accidentally delete the surrounding classes/divs that create the more detailed structure.
I'm pretty familiar with Joomla and have built quite a few sites, but I've not used an cck tools and was hoping not to have to do that in this case, though maybe now is the time to learn.
Any advice / recommendations would be welcome !
Richard
Maybe ContentBuilder could do in your case, it's fairly easy and creates super-simple code, I've accomplished similar tasks with it. You provide the user with 3 fields (one per column) and create a layout for its display.
Another alternative is possibly even easier: you could override the use of the page functions in a template override of com_content/article, instruct the user to insert at most 2 page breaks, and use the page breaks to build the layout as you require.
If your sites is upgraded to the Joomla 3 you can use the build-in Bootsrap to do the layout.
You can find some more information how you can achieve this in the following page:
http://twitter.github.io/bootstrap/scaffolding.html#gridSystem

backbone.js load different html

i've been posting alot questions lately on stackoverflow due to my issues i'm facing recently and you guyz have realy helped me alot.
MY Question:
I'm working on backbone.js and i've worked on codeignitor on my project. Now my question is in ci, i can load views directly from ci view and can display dynamic html easily ( working fine for me). problem is i've to shift my js code and functions and ajax calls to backbone.js and i'm pretty much at the start of this project. i'm not clear on how can i show entirely new page html on some events in backbone.
my question Not clear? let me explain further.
Explanation:
i mean i've some an index page and all of things load in this page ( sliders , footers etc etc ). whenever any item is clicked to see the details, ci calls the appropriate methods and gives me the html which displays that product in an entirely new page ( without loading ) with only image of that product and some other options for the product. it's pretty easy with ci, but how can i do this with backbone.js to show up different pages or entirely different html from index page and not showing other stuff of index page.
i can work out how to move and design the logic behind it but i'm not getting the picture of how can i load these different html for different events ( like about button should show about us page, featured category should show featured products all in that main index file.)
I'm really desperate to get some directions.
thnx guyz
I think you were meant to say you want to make single page application.
Yes, backbone best idea to do so. You will required following :
template ( should be inside <script type="text/template"> and </script>)
backbone view
backbone model
backbone router

Differences between MVC and View First approach in web development

Today when I searched on the internet I saw the View first approach in web development of Lift framework. Can somebody tell me the differences between view first and MVC approach ?
Thank you very much
View first is based not on a model and a controller, but mostly interested in the view. Many problem domains do not neatly compose in controllers and models. Think about a ecommerce site, the shopping cart exists on all pages, but should every controller control it? Personally in MVC too much of my time is spent thinking about how to logically make the problem fit into MVC than just coding. View first takes away this controller / view / model and instead just has a view which in Lift can call "snippets". It is almost a superset of MVC since if you wanted you could only have a single snippet per page, but Lift allows you to do much more. Snippets can be cross cutting concerns or very page specfic logic.
From the lift website..
Lift is different [from MVC]. For HTML requests, Lift loads the view first and builds your page from the view. Lift also supports REST style requests for non-HTML data. (See 11 on page 1↑) “Why?” Because complex HTML pages rarely contain a dominant piece of logic... a single controller... but contain many different components. Some of those components interact and some do not. In Lift, you define the collection of components to be rendered in the resulting HTML page in the view.
When your using lift, you basically have a view(page) and from this you could incorporate any snippet(app) that you have without much of the antics you'd normally have to do in an MVC framework/environment.
Basically you don't have to choose what the most important thing on the page is just what you want to add to a page and then add it.

Orchard CMS Render module view in homepage

I'm trying to render a view, defined in a module, in the main site homepage (~/) as it's main content. If the user is not authenticated, i need to show a login/register view instead.
The logged-in view lives in one module (Product Module) and the login/register view lives in another (Account Module). The logged-in view requires a service call to fetch data based on the user's products. I'm currently using standard mvc to render these views and fetch the data they require in their controllers.
Can this be accomplished by treating these views as shape templates? If so, are there any examples of pulling in views to the homepage like this? Or is there a better way of achieving this?
I have tried implmenting IHomePageProvider to return my own homepage ViewResult within the Product module, but without any success.
Cheers.
First, you might want to look into widgets and layers. You could define a layer for authenticaed users, and one for anonymous users, and attach widgets to those layers to achieve what you want. That might be the best way for you to accomplish this. Look in the Orchard docs for examples on how to do this.
I have done a similar thing before using custom controller and a lot of custom logic. Because of my specific requirements widgets and layers would not work for this. All the content on the page needed to change depending on some inputs, and widgets and layers were not going to be well suited for this. What I did was create a custom controller, and a corresponding Route with a high priority (so the Route takes precedence over any others that want to be the home page). I didn't mess with IHomePageProvider at all.
In the controller action I pulled the data necessary, and created the shapes I wanted, and then returned a result like this: return new ShapeResult(this, homePageShape);
homePageShape is constructed like this, right before the return statement:
// Create personalized home page shape:
var homeShape = _orchardServices.New.CustomHome(
SomeShape1: someShape1
, SomeShape2: someShape2
, SomeModel1: someModel1
...
);
This creates a shape called CustomHome, and orchard will automatically look for a template called CustomHome.cshtml in the views folder of your module.
I created several shapes (all the "someShapeX" vars you see above). Mostly they are created from content parts via the BuildDisplay() method. The content parts are queried using IContentManager, and the shapes are created like this (this example is for a slide show shape):
dynamic sliderShape = _contentManager.BuildDisplay(sliderPart, "Detail");
You can put logic in the controller to build the shapes you want depending on whether or not the user is logged in. In CustomHome.cshtml you would render a shape like this:
#Display(Model.SomeShape1)

How to display multiple widgets on the same page using MVC

I'm a bit confused about how MVC works and I can't find anything but basic examples.
I want to make a kind of widget-based design; you can choose various widgets to go on your page. Each widget should be responsible for itself - it should have a controller and a view. But what about the main page? Suddenly I've got a page with lots of controllers on it!
The obvious thing to do is to embed the controllers in the view somehow... This is my widget {SomeWidget} but I've read that "breaks the MVC paradigm".
Some widgets will need to POST to different urls (like a search box goes to the result page) and some will need to POST back to the same URL (like adding a comment to an article brings you back to the article).
To top things off, the user should be able to edit the HTML around the widget - for example if they want a search box on the right, they can type <div style="float: right;">{SearchController}</div> (in my paradigm-breaking world)
I am not very good at web programming, but i believe, from the example you described, that there should be one model, one view and one controller for the entire page. Now the view itself should contain the views for every widget in the page (and the same goes for the page controller) to which it dispatches the messages it receives.
Conceptually there is a lower level of MVC (for widgets) and a higher level of MVC (for the page). And the MVC paradigm won't be broken. Now you can edit the HTML around the widget, it changes the page model (and not any widget model).
Hope this helps !
To add to #Benoît's comment:
The Symfony framework handles this with components. Each component is a self-contained MVC instance that can be embedded into another view. It cannot be instantiated to respond directly to web requests like the normal MVC instance (a module/action pair). It can only be embedded into another MVC view.
As a side note: Symfony also treats plugins as their own complete MVC instance, complete with its own schema, models, controllers, config files, views, et al.
In your case, each component would be its own MVC instance and the app would stitch these components together. Each component would be responsible for how it responds to a form submit.
MVC doesn't mean there is ONE view and ONE controller. It just means the app logic is stored in models, the controller glues things together, and the view builds the display. It's a formal and logical separation of logic and presentation.
One of the best, short, and simple books I have found on MVC is this one handed out last week at the PDC 2008 expo:
http://www.apress.com/book/view/1430216468
Not only does it cover MVC's concept, but its comparisons to other concepts such as Ruby on Rails and MVP methodology.
In addition, it goes into the entire reason MVC exists by describing it's seperation of concerns, and why it should not only be at the UI level - but down into your actual layers or IoC structure of your business objects and DAL.
I'd highly recommend this book as he covers best practices, in just 110 pages or so.
And no, I do not work for FirstPress or related to them at all. I just liked the book, and finally someone I agree with.
The best information I've found on doing widgets in ASP.NET MVC is on Steve Sanderson's blog. He explains his concept of partial requests which is a different technique than sub-controllers.
http://blog.codeville.net/2008/10/14/partial-requests-in-aspnet-mvc/
Partial Requests are easy You’ve heard of partial views, so how about
partial requests? Within any MVC
request, you can set up a collection
of internal partial requests, each of
which can set up its own internal
partial requests and so on. Each
partial request renders a plain old
action method in any of your plain
regular controllers, and each can
produce an independent widget. I’m
calling them partial “requests” rather
than “controllers” because they run a
proper MVC request-handling pipeline
that’s compatible with your routing
system and your controller factory.
Still, as with subcontrollers, all the
control remains in controllers, and
the view can be ignorant.
There are a lot of variations on the MVC theme and a lot to consider before coming to a conclusion as to the design of your particular system. Most of the latest, popular web based systems look to IoC as the guiding principal. Usually, some kind of framework component is the controller that uses some kind of configuration to invoke the proper template as the view and to couple it with the appropriate object hierarchy as the model. Most of these systems include an extensible GUI widget library to be used by the templates. You can add your own widgets but it is not best practice to hard code your widgets to a specific object hierarchy. That IoC link also talks about components and services which should give you some direction on how to avoid that hard coding.
ASP.NET MVC is well suited for a widget dashboard mashup type page.
Take a look at this session from PDC 2008.
You will probably want to use the Ajax helpers to update the islands of data in each widget. Here is a snippet of how you could put a calculator on any page but keep the code independent.
View Snippet:
<script type="text/javascript">
function OnFailure(error) {
alert("We have encounterd an error " + error);
}
</script>
<% using (Ajax.BeginForm("Add", new AjaxOptions{UpdateTargetId="sum", OnFailure="OnFailure"})){ %>
<%= Html.TextBox("x") %> +
<%= Html.TextBox("y") %> =
<span id="sum">?</span>
<input type="submit" value="AddEm" />
<% } %>
Controller Snippet:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Add(string x, string y)
{
int sum = int.Parse(x) + int.Parse(y);
return Content(sum.ToString());
}
I think JarrettV's and jcoby's answers are closest.
I've come to know subcontrollers as Hierarchical MCV (HMVC). The idea is that you "pull" content (a view populated by a subcontroller) from the parent view template instead of "pushing" data to the template from the controller. So instead of needing to edit both the controller and view to add a widget, you just call the widget from the view. There are libraries to accomplish this in the php frameworks CodeIgniter (Modular Extensions) and Kohana (Dispatch, and Component).

Resources