Welcome Guest, Not a member yet? Register   Sign In
Using partial views
#11

[eluser]Michael Wales[/eluser]
Ah - you need HMVC.
#12

[eluser]Madmartigan1[/eluser]
[quote author="Michael Wales" date="1241823291"]Ah - you need HMVC.[/quote]

Ouch.

Thanks..

So this is the best way to display a simple db-generated list on a few pages without duping code? Writing sql into views would work, but is terrible practice.

Is it time for me to learn rails yet?

I really want to love Codeigniter, sorry to be curt.
#13

[eluser]Michael Wales[/eluser]
There are other ways as well, Wick is a pretty simple solution. CodeIgniter (and Rails for that part) just weren't designed to support modularized elements on the page. Even in Rails you would need to return a list of posts, then pass that object to your partial, within every Controller.
#14

[eluser]Madmartigan1[/eluser]
[quote author="Michael Wales" date="1241825396"]There are other ways as well, Wick is a pretty simple solution. CodeIgniter (and Rails for that part) just weren't designed to support modularized elements on the page. Even in Rails you would need to return a list of posts, then pass that object to your partial, within every Controller.[/quote]

Wow, Wick looked great and then this happened:
Code:
Warning: Call-time pass-by-reference has been deprecated in C:\webroot\application\libraries\Wick.php on line 126
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Events_model::$db

Filename: models/events_model.php

Line Number: 23

Fatal error: Call to a member function select() on a non-object in C:\webroot\application\models\events_model.php on line 23

Followed the instructions to a T. (what's the "T" mean anyway? lol)
Maybe I should mention I'm running CI 1.7.1

Seriously, let's say you want to list a few items from a database on page X and Y but not Z. No rewriting code for each page. Without a framework it is so simple with file includes, just include the list file (which consequently includes the mysql/php needed to generate it) in page X and Y. Why is this so difficult? This is such a simple thing that you can almost count on every web app having to be able to do.

*bangs head on desk*

Michael, I really appreciate the help. Thank you. I'm just not too sure you're clear on what I'm trying to do.
#15

[eluser]Madmartigan1[/eluser]
Sorry to doubt you Michael...

from some random blog
http://sriesland.com/wpblogs/?p=7
On a side note, I find it really distasteful that in CodeIgniter you are not able to forward between controller actions without actually sending out an HTTP redirect to the client using the URL helper. This ability to load other controller actions without “bouncing” the client to the right place should definitely be included in any decent MVC framework and I am dumbfounded not to find it in CodeIgniter. I suppose one work around that has been sited is HMVC; however that could require you rearranging your MVC controllers into a new directory structure and seems like a bit of a workaround.

This is coming from someone who supports CI quite a bit.
#16

[eluser]Michael Wales[/eluser]
No, no need to feel sorry! It is a common complaint against CI and the answer is, CI just wasn't designed to perform this modularized concept that you are attempting. There are a variety of plugins/extensions out there to help (I've only named 2 - I'm sure a thorough search will reveal more).

If you are deadset on this functionality - and the plugins aren't working for you - I have nothing else to say other than CI may not be the framework for you. Not meant in a demeaning way, just the facts. CodeIgniter isn't for everything.
#17

[eluser]Madmartigan1[/eluser]
Well I talked to a friend who is a rails developer and explained my issue. Note that I am new to MVC structure. Anyways, his "rails solution" was just as involved.
I'm going to take a closer look at HMVC, it seems really "unobtrusive", and to be honest I kind of like the structure it forces.

I know you are involved somehow with CI Michael, so I felt you were trying to put the best face on CI as possible rather than address my issue. In the event that we meet again just understand that I do appreciate your help.

I'm not used to people actually being helpful in forums.
#18

[eluser]Nexus Rex[/eluser]
[quote author="Michael Wales" date="1241815382"]I recently posted how to implement partial views inspired by Ruby on Rails on my blog. If you don't want to go that far all out - just take a look at the code for views/layout.php and each individual view file.[/quote]

Michael,

I have spent hours trying to use your method from that blog post, and can't get CI to find the MY_Controller class...

File: system/application/libraries/My_controller.php
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// application/libraries/My_controller.php

class My_controller extends Controller {

  var $partial = 'debug/echo';

  function My_controller() {
    parent::Controller();
    $this->_get_partial();
    $this->_get_model();
  }
  
  function _get_partial() {
    $uri = $this->router->class . '/' . $this->router->method;
    if (is_file(realpath(dirname(__FILE__) . '/../views/' . $uri . EXT))) {
      $this->partial = $this->router->class . '/' . $this->router->method;
    }
  }
  
  function _get_model() {
    $uri = substr($this->router->class, 0, -1);
    if (is_file(realpath(dirname(__FILE__) . '/../models/' . $uri . EXT))) {
      $this->load->model($uri);
    }
  }

}

When I try to create a members.php controller that extends My_controller I get an error.

FATAL ERROR: Class 'My_controller' not found in /home/latinole/public_html/directory/system/application/controllers/members.php on line 3

I have tried autoloading the library, moving it to /system/application/controllers/, all to no avail.
#19

[eluser]Dam1an[/eluser]
The file should be caled MY_Controller.php, its case sensitive (on Linux) and even on Windows, you should call it like that for consistency as per the style guide
#20

[eluser]Nexus Rex[/eluser]
Thanks Dam1an. I find the naming schemes in CI to be very arbitrary.




Theme © iAndrew 2016 - Forum software by © MyBB