Welcome Guest, Not a member yet? Register   Sign In
  ORM-like model implementation in CI
Posted by: El Forum - 08-09-2007, 02:24 AM - No Replies

[eluser]bAum[/eluser]
Hi all,

I am new to CI, and I was wondering what the general approach is to implement models that represent database records in CI.

In my understanding, CI models as they are presented in the user guide, for instance, are not a representation of some database record, but rather of a whole concept (the user guide contains the example of a "blog", not of a "blog post"). And there is the fact that CI's default behavior when loading a model is to create a single instance of that model having the model's name. This also suggests that the intent is to create a model once, like some data-oriented library.

I prefer, however, the orm/activerecord approach, where a model instance represents some record of my database, which means that I'll generally deal with several instances of the same model. Yet, as far as I understand, all loaded models are part of the CI namespace, and if I load a model twice with the same name (just imagine a loop over blogposts, for each one I would load a blogpost model which I call temp), I'll get an error that I'm using a name that already exists.

This naming conflict was just an example, I'm sure that this is not the only issue I'll have to deal with. So what would people here suggest me? How would you implement this stuff in CI (well, I could create model classes not "linked" to CI, but this would somehow undermine CI)?

Many thanks.


  Controller / function loading twice?
Posted by: El Forum - 08-08-2007, 11:45 PM - No Replies

[eluser]mipa[/eluser]
I have a bizarre issue with the following behavior:

Adding parameters to a URI causes the application to load twice, the second time butchering all URI segments after the third one.

The pages use the OB Session library.

Have I funked up some configuration settings somewhere? Or is there some other reason for this behavior? Any insight would be appreciated!


  Model Not Loaded?
Posted by: El Forum - 08-08-2007, 07:36 PM - No Replies

[eluser]Vik[/eluser]
I've just started working with CI, I have a newbie question.

I have a controller that contains this code:

Code:
<?php
class Alloy_Planner extends Controller {

    function Alloy_Planner()
    {
        echo ('a');
        parent::controller();
        echo ('b');
        $this->load->model('add_alloys_model');
        echo ('c');
    }
    
    function index()
    {
        $data['title']= 'Alloy Planner';
        $this->load->view('alloy_planner_views/add_alloys_view', $data);
            
    
    }
    
    function search()
    {
        $data['title']= 'Alloy Planner';
        $alloy_name = $this->input->post('alloy_name');
        
        $data['search_results'] = $this->add_alloys_model->getSearchResults($alloy_name);
        
        $this->load->view('alloy_planner_views/search', $data);
            
    
    }
}
?>

I have a file called "add_alloys_model.php" (well, it's actually not alloys, it's something else, but I'm not ready to announce it yet) in the models folder. But, it looks like it's not being loaded. The echo statements in the code print out 'a' and 'b', and then everything stops. The rendered html page is completely blank.

What should I check in order to fix this?


  how do you deal with your variables?
Posted by: El Forum - 08-08-2007, 05:05 PM - No Replies

[eluser]batteries[/eluser]
I don't mind passing variables around in a "procedural" fasion.. But, when dealing with a complex execution, i will use a more oop approach and set my data into the relevant model as private variables.

So my question, how do you guys do it? is there a best practice? For my current project i want to deal with my data exclusively in the oop way but i'm not sure if i should validate before i set the data to variables, or to set the data as soon as i get it..

Thanks


  Forms – Dynamic input names
Posted by: El Forum - 08-08-2007, 03:17 PM - No Replies

[eluser]webdude[/eluser]
My form input names are generated using a product code held in my database. As I don’t know their names until the page loads how do I get their values once the page has been submitted.

Code:
<?=form_open($_SERVER['REQUEST_URI']."add");?>
  <?php foreach($derivatives->result() as $row):?>
    &lt;?=$row->code?&gt;</strong><br />
    <label for="code">QTY</label>&lt;input name="&lt;?=$row-&gt;code?&gt;" type="text" id="&lt;?=$row->code?&gt;" value="1" size="3" /><br /><br />
  &lt;?php endforeach;?&gt;
  &lt;input type="submit" value="Submit"  /&gt;
&lt;/form&gt;

outputs

Code:
&lt;form action="http://www.some-domain-name.co.uk/products/solenoid-valves/direct-solenoid-valve/add" method="post"&gt;      6B37-A3-S-P</strong><br />
    <label for="code">QTY</label>&lt;input name="6B37-A3-S-P" type="text" id="6B37-A3-S-P" value="1" size="3" /&gt;<br /><br />
      6B37-A3-S-N</strong><br />
    <label for="code">QTY</label>&lt;input name="6B37-A3-S-N" type="text" id="6B37-A3-S-N" value="1" size="3" /&gt;<br /><br />
    &lt;input type="submit" value="Submit"  /&gt;
&lt;/form&gt;


  Best way to solve unwanted uri characters.
Posted by: El Forum - 08-08-2007, 02:56 PM - No Replies

[eluser]eedfwChris[/eluser]
Basically I have something like...

/view/2

where 2 is the id of some article.

What is the best way to prevent people from typing say... "e" in there and generating a SQL error?


  Best practice for simple HTML and PHP code reuse in views?
Posted by: El Forum - 08-08-2007, 01:46 PM - No Replies

[eluser]mazaka[/eluser]
Hi all, I just started using CI, and it looks very promising!

I searched the forum for good ways of reusing and including code in views, but havent found exactly what I am looking for.

I simply want to include pageheaders, footers, simple nav bars and CSS info (yeah I have to have it inline, I cant link it to external css files for this proj. Its for phones. Phones dont like that.)


Until I find a better way, I do this in a VIEW file:

Code:
&lt;head&gt;
        &lt;?php require dirname(__FILE__).'/../myOwnIncludeFolder/inc.css.xhtml.php'; ?&gt;
&lt;/head&gt;

Does someone have the correct approach?

thanks!


  Newbite Correct Site Structure Set Up Question
Posted by: El Forum - 08-08-2007, 11:46 AM - No Replies

[eluser]opel[/eluser]
Hi I'm new to Code Ignite and still working through 1st few tutorials. I plan to make a small CMS system and want to check my plan for setting up my CI structure is correct.

Usually when I create dynamic sites I have an admin directory that is secured by user login system. The database structure is then fed out to the public pages as usual.

Using CI's MVC would I create an "admin" controller with admin views for adding news, adding links etc. Then controllers/views for the public sections ?


  Multiple Views & Dynamic Data
Posted by: El Forum - 08-08-2007, 11:27 AM - No Replies

[eluser]Freakish_05[/eluser]
Evening all,

Further to my thread about multiple smarty views with CI, I've ditched smarty is it seemed to make things far more complicated than using CI's views.

I how have a new problem....
My sidebars and navbars are very often run from databases and frequently use URL variables to return data.

What is the best method of doing this in CI? The php code obviously needs to run before CI outputs the final view.
If I understand the MVC approach correctly, I should be creating plugins for all of my sidebar elements and then wrapping them all up in an addtional plugin function which is called in each of my controllers.

All comments greatly appreciated,
Freakish_05


  Difficulty understanding how to code up a webpage
Posted by: El Forum - 08-08-2007, 10:23 AM - No Replies

[eluser]Carlton[/eluser]
Hi People,

I have been looking through the code igniter documentation for about 2 weeks now and started writing some code but having difficulty grasping how it is you should create a reusable structure for a web page.

Previously I would have created nav bars, side navs in seperate php files and used the include function to place them in certain places of a template. If I were to do something similar in Code Igniter would I need to use multiple views...e.g....

Code:
$this->load->view('header_view', $data);
$this->load->view('nav_view', $data);
$this->load->view('content_view', $data);
and the data variable may contain page specific elements...such as a title...is this approach correct?

Also, how can I avoid calling 3 views on every page...would I need some sort of web page class that each page (e.g. login, search, news) extends and can simply call some sort of method that renders my main structure (i.e. create header, nav and body...then if I need to alter this I can just do it in one place)

Hopefully this question makes sense, I think I will look into buying a book which covers OO web page development or something as I think I am missing something Smile

C


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Latest Threads
Heads up for users using ...
by InsiteFX
3 hours ago
The Hidden Cost of “Innov...
by fcoder
3 hours ago
tool bar not showing
by InsiteFX
9 hours ago
Tool bar not showing
by InsiteFX
10 hours ago
Validation does not appea...
by grimpirate
Yesterday, 01:55 PM
Block IP addresses of bad...
by grimpirate
Yesterday, 01:47 PM
Override Router
by grimpirate
Yesterday, 01:30 PM
CodeIgniter.com - Report ...
by Vikas Mehta
06-30-2025, 10:30 AM
best way to store tokens ...
by ahallrod
06-30-2025, 10:03 AM
Hey Now it is a time for ...
by J0shflynn
06-29-2025, 06:44 AM

Forum Statistics
» Members: 154,325
» Latest member: yo88zkcom
» Forum threads: 78,435
» Forum posts: 379,706

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB