Welcome Guest, Not a member yet? Register   Sign In
  best controller architecture
Posted by: El Forum - 06-08-2008, 11:08 AM - Replies (4)

[eluser]spherop[/eluser]
I am new to CI and to some degree the MVC approach.

I want to try to understand something before i get too tangled in one approach or another.

I am using CI and jQuery for a new site in which most all of the functionality will be within a single page. Different data and UI behavior will occupy different parts of the screen, be loaded dynamically, and be able to be shown and hidden and so forth.

What I am unsure of is whether to use a single controller - to govern this single page. Or to use a different controller for each part of the page that deals with different data/behavior.

Say for example, I have a comments pane on the left, a video blog in the middle pane, and a friends view in the right pane. Would I most likely end up with a distinct controller for each of these 3? Or 1 controller that will handle this whole page?

I am getting my bearings here - so forgive me if this is obvious or I am missing some key concepts in the line of questioning.


  Extend Active Record Class
Posted by: El Forum - 06-08-2008, 03:39 AM - Replies (3)

[eluser]stoefln[/eluser]
Is it possible to write my own container class for the data?
i mean somehow this way:

Code:
$query = $this->db->get_where('types',array('id' => $typeId));
$type = $types[0];
$type->myUserMethod();


  Default Controller
Posted by: El Forum - 06-08-2008, 02:26 AM - Replies (8)

[eluser]kenjis[/eluser]
If you access to
http://localhost/index.php

you can see controllers/welcome.php.

And if you access to
http://localhost/index.php/hoge (hoge is a empty directory)

also you see controllers/welcome.php.

Is this the specification of default controller?


I expect:

When I access to
http://localhost/index.php/hoge (hoge is a directory)

I see controllers/hoge/welcome.php (if exsits) or 404 Page Not Found.


  MS SQL does not work
Posted by: El Forum - 06-08-2008, 02:24 AM - Replies (8)

[eluser]=G-Man=[/eluser]
Hello, I just started playing with CodeIgniter and am converting an older Full PHP site over to it. But I'm having a huge issue with MSSQL, as soon as i call $this->load->database() the page just stops loading and I get a plank page, No errors from codeigniter, or in the PHP error log. I saw a few posts about this and they all seemed to be upgrading to 1.6.2 so I tried a few earlier versions (1.4.1, 1.5.3, 1.6.0) and thay all do the same thing as soon as I try to load the database functions.

here is my database.php

Code:
$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "sql1";
$db['default']['username'] = "sa";
$db['default']['password'] = "<password>";
$db['default']['database'] = "lin2admin";
$db['default']['dbdriver'] = "mssql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

<password> being a mask for the forum.

I know the DB server is running, because I can connect to it via the MS SQL Management Studio. There is also no firewall on the SQL server itself and the WEB server is on the same local network as the SQL server and my Development computer that I can connect to the DB server with the management studio.

Thanks for your help.
-Don


  Javascript Nightmare
Posted by: El Forum - 06-07-2008, 10:27 PM - Replies (18)

[eluser]psdtocode[/eluser]
Hello,

I'm new to both CI and JS, however, I can't explain what is going on, and help from others isn't working. Basically, I am making a simple todo list, and I want to use JS/AJAX to get familiar with JS more. However, I'm having trouble just including JS files.

First, I was doing a relative path, such as src="prototype-1.0.6.2.js" (I've also tried jQuery), which didn't work. I then tried a couple different absolute paths, which didn't work as well. Finally, I searched on here and found a script_url helper (similar to a link_url()) helper, which doesn't work for me. Which ways are you able to include JS files (hopefully without a helper), because I can't seem to get it working.

I know it's not including because I can't use simple $() functions, and normal JS functions work (such as alert()Wink. In Safaris error viewer, it shows up an error when I try to use relative paths, and nothing shows up when I try to go to absolute paths. Any and all help is appreciated.

Just a note, I'm including it from a view file.

Thanks,
Andrew


  global controller??
Posted by: El Forum - 06-07-2008, 10:05 PM - Replies (2)

[eluser]nuttynibbles[/eluser]
hey guys, is there a way to extend controller from another controller. my controllers basically initiate almost the same variable in the constructor and I was thinking if I could do a parent controller which extends from "Controller" libraries and basically the rest of the controllers will extend from my created parent controller.


  Class and Function URI segments redundant - how to work around them?
Posted by: El Forum - 06-07-2008, 09:56 PM - Replies (1)

[eluser]Aquillyne[/eluser]
There are plenty of occasions when I don't actually need to specify my class and function, but I am forced to. Is there a way to get straight into the "id" part, i.e. the part that is passed as a parameter?

For instance, I want a welcome controller that does nothing more than output something from the URI. I want to go to mysite.com/<foo> and see <foo> on the page - that's it.

Without CI this is ridiculously easy. The index.php file just echoes what's in the $_GET. A .htaccess file, as with CI, reduces mysite.com/index.php?=foo back to mysite.com/foo. Easy. But how to do this with CI?

A similar case. A function in my welcome controller accepts a parameter. Why must I go to mysite.com/welcome/function/param rather than just mysite.com/function/param, when the "welcome" has been implicit all along? This is basically the same question as before: why do I have to specify mysite.com/welcome/index/param rather than just mysite.com/param when the "welcome" and "index" were previously implicit?

Note that I only want this to happen on particular pages, which is again very easy without CI. My "foods" page may have no further functions, and hence just immediately accept a parameter. I can use mysite.com/foods.php?=param, or mysite.com/foods/param to do this. But in CI, the foods/param is assumed to refer to a function "param" in the "foods" class. How do I specify, only on the "foods" page, that the second URI segment is to be passed as a parameter?

Is there a way to work around this? Thanks for any help.


  Error 'Undefined property' when loading model to controller
Posted by: El Forum - 06-07-2008, 09:25 PM - Replies (8)

[eluser]Tortoise[/eluser]
Hello to everyone!

I have the code:
news.php:

Code:
&lt;?php
  class News extends Controller
  {
    public function ru()
    {
      $data['xml_lang'] = 'ru';
      $data['title'] = 'Официальный сайт брутал-дэт группы Fleshbomb - Новости';      
      /*$this->load->helper('url');
      $data['main'] = anchor('news/ru', 'Главная');*/
      $data['published'] = 'Опубликовано';
      $this->load->model('news_model');
      $data['news'] = $this->news_model->get_last_three_entries($data['xml_lang']);
      $this->load->view('newsview', $data);
    }
    
    public function en()
    {
      $data['xml_lang'] = 'en';
      $data['title'] = 'Fleshbomb brutal-death band Official Site - News';
      /*$this->load->helper('url');
      $data['main'] = anchor('news/en', 'Main');*/
      $data['published'] = 'Published';
      $this->load->model('news_model');
      $data['news'] = $this->news_model->get_last_three_entries($data['xml_lang']);
      $this->load->view('newsview', $data);
    }
  }
?&gt;
news_model.php:
Code:
&lt;?php
  class News_model extends Model
  {
    public function __construct()
    {      
            parent::Model();
            $this->load->database();
    }
    
    public function get_last_three_entries($lang)
    {      
      $sql = "SELECT p_date AS date, p_title_$lang AS title, p_content_$lang AS content FROM site_news LIMIT 3";            
      $query = $this->db->query($sql);
      return $query->result_array();
    }
  }
?&gt;
and newsview.php:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="&lt;?php echo $xml_lang; ?&gt;" lang="&lt;?php echo $xml_lang; ?&gt;"&gt;
&lt;head&gt;
    &lt;title&gt;&lt;?php echo $title; ?&gt;&lt;/title&gt;
  &lt;meta name="keywords" content="brutal-death, grindcore, grind-core, goredeath, gore-death, fleshbomb, nosorog" /&gt;
  &lt;meta name="description" content="Moscow gore-death band official site. Full discography, biography, gigs, videos" /&gt;
  &lt;link rel="stylesheet" type="text/css" href="../../system/application/media/css/style.css" /&gt;
&lt;/head&gt;  
&lt;body&gt;
    <div id="sidebar-left">
        <ul id="menu-list">
            <li><a href="#">Menu item</a></li>
        </ul>
    </div>
  &lt;?php foreach($news as $item): ?&gt;
  <div class="news-block">    
    <h3 class="news-title">&lt;?php echo $item['title']; ?&gt;</h3>
    <div class="news-date">&lt;?php echo $published . ': ' . date('d.m.Y H:i:s', $item['date']); ?&gt;</div>
    <div class="news-body">&lt;?php echo $item['content']; ?&gt;</div>
    <hr />
  </div>
  &lt;?php endforeach; ?&gt;
&lt;/body&gt;
&lt;/html&gt;
On my local server (MAMP 1.7.1) it works just fine. Even if I used $this->load->model(Uppercase_name) or $this->load->model(lowercase_name).
But when I put it on hosting server I have get error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: News::$news_model
Filename: controllers/news.php
Line Number: 12
Fatal error: Call to a member function get_last_three_entries() on a non-object in /pub/home/artwiko/htdocsfb/dev/system/application/controllers/news.php on line 12
For the /news/ru.html.
And:
Fatal error: Call to a member function get_last_three_entries() on a non-object in /pub/home/artwiko/htdocsfb/dev/system/application/controllers/news.php on line 24
For the /news/en.html
I can't understand what I doing wrong.
Could somebody help please?


  Advanced MySQL: Active Record Query not working properly?
Posted by: El Forum - 06-07-2008, 09:04 PM - Replies (6)

[eluser]MercuryLime[/eluser]
Do you have an idea how to write:

Code:
$query = $this->db->query('SELECT c.title, c.description, r.completion_notes, r.outcome FROM challenges AS c, records AS r WHERE c.id = r.challenge_id AND r.user_id = ' . $user_id . ' AND r.outcome = "ip" LIMIT 100');

as an Active Record Query?

I tried the following, but it returned 0 results.

Code:
$this->db->select('c.title, c.description, r.completion_notes, r.outcome');
        $this->db->from('challenges AS c, records AS r');
        $this->db->where(array('r.challenge_id' => 'c.id', 'r.user_id' => $user_id, 'r.outcome' => 'ip'));
        $this->db->limit(100, 0);
        $query = $this->db->get();

Help would be appreciated!


  How to load a view for the error page?
Posted by: El Forum - 06-07-2008, 08:57 PM - Replies (25)

[eluser]Aquillyne[/eluser]
Hi, I'm new to CI. I'm very impressed so far but have a question - could anyone help out?

I want error messages from my site to appear as messages in one of my normal views, rather than as hard-coded messages from the /errors folder. Is there a way to load a view within/instead of an error message?

Thanks.


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

Username
  

Password
  





Latest Threads
codeigniter4/queue Not lo...
by mywebmanavgat
2 hours ago
Array to HTML "Table"
by HarmW94
3 hours ago
shortcodes for ci4
by xsPurX
5 hours ago
TypeError when trying to ...
by b126
Today, 12:04 AM
Webhooks and WebSockets
by InsiteFX
Yesterday, 10:39 AM
Retaining search variable...
by pchriley
Yesterday, 05:46 AM
Reading a session variabl...
by xanabobana
Yesterday, 05:05 AM
Update to v4.5.1, same us...
by kenjis
04-17-2024, 07:47 PM
Codeigniter 4 extend core...
by Semsion
04-17-2024, 05:08 AM
v4.5.1 Bug Fix Released
by lokman
04-16-2024, 02:12 PM

Forum Statistics
» Members: 84,584
» Latest member: kalyt72
» Forum threads: 77,559
» Forum posts: 375,899

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB