Welcome Guest, Not a member yet? Register   Sign In
  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.


  simple & helpful DB class for CI
Posted by: El Forum - 06-07-2008, 08:18 PM - Replies (4)

[eluser]vps4[/eluser]
It’s simple and useful MySQL DB class.
I modify it from WordPress2.5.1 wp-db.php

It also automatic load DB config from CI config file.

Usage:

just put it in your CI app library folder, usually in system/application/libraries
and name Db.php

now , you can load the library anywhere, or set it automatic load in autoload config file

Code:
$this->load->library('db');


these method is better than CI database, only ONE line code.
Code:
$this->db->get_var($sql);
$this->db->get_row($sql);
$this->db->get_col($sql);
$this->db->get_results($sql);


enjoy it!!!

I can’t post the code to here, because it’s so long

please get it from

http://www.21andy.com/blog/20080607/1156.html

anyway, sorry for my poor english.


  mysql_result Equalvilent in CodeIgniter
Posted by: El Forum - 06-07-2008, 06:56 PM - Replies (2)

[eluser]helloadam[/eluser]
Howdy,

I am converting a backend application into CodeIgniter. I have came across a small issue that is driving me nuts.

I have searched the wiki/user guide and forums but found no such of a solution.


My application is doing something like so,

Code:
$get_settings = $this->db->query("SELECT `data` FROM `". $this->tablePrefix ."settings` WHERE `vkey`='t_cstatusupd'");
$settings = mysql_result($get_settings,0,'data');


But I am unsure how to handle the mysql_result part. I noticed the ->row object is similar to the mysql_result part however, it does not accept the other two parameters that the script requires.


Any tips, suggestions, etc?



Thanks,
Adam


  MPT Tree: Tree Admin Error
Posted by: El Forum - 06-07-2008, 02:30 PM - Replies (1)

[eluser]lightnb[/eluser]
I'm trying to get the tree admin system working, but encounter an error:

Code:
Message: Undefined index: slug

Filename: controllers/treeAdmin.php

Line Number: 159

Any ideas?


  MVC Question
Posted by: El Forum - 06-07-2008, 02:18 PM - Replies (5)

[eluser]Matt Crowson[/eluser]
If I have static information on a page does that go in the model, view, or controller?


  FIXED: Calling other model functions from within same model
Posted by: El Forum - 06-07-2008, 12:45 PM - No Replies

[eluser]MercuryLime[/eluser]
I've searched around on this forum looking for help, but found no solution.

Basically, I am calling another function in my model code and I have identified that the specific line is breaking the code. I don't know why!

Here is the model (irrelevant functions removed).

Any ideas why that line is breaking the code?

Code:
&lt;?php

class Challenges extends Model {

    function Challenges()
    {
        parent::Model();
    }
    
    function get_challenge ($condition = array()) {
        // Returns challenge object based on supplied conditions array (usually, single associative array with key 'id')
        $query = get_where('challenges', $condition, 1, 0);
        if($query->num_rows() == 1) {
            return $query->row();
        }
        else {
            return FALSE;
        }
    }
    
    function get_current_challenge ($user_id) {
        // returns object of the challenge table row (currently with keys 'id', 'title', 'decription', 'tags', 'date_created', 'submitter_id', 'approved')
        // 1) Determine the challenge_ id of the current challenge of the user
        // 2) Return the object of the challenge table row with that id
        $this->db->select('challenge_id');
        $query = $this->db->get_where('records', array('user_id' => $user_id, 'outcome' => 'ip'), 1, 0);
        if($query->num_rows() > 0 ) {
            $row = $query->row();
            return $this->get_challenge(array('id' => $row->challenge_id));
// THIS LINE IS BREAKING THE CODE ^^^
        }
        else {
            return FALSE; //  User has no current challenge...? Deal with this.
        }
    }
    
}
?&gt;

EDIT: *groan* Yes, it is possible to access different functions in the same method. I made a mistake using the Active Records get_where function.

Hours down the drain!


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

Username
  

Password
  





Latest Threads
Codeigniter Shield Bannin...
by kenjis
14 minutes ago
Best way to create micros...
by kenjis
1 hour ago
How to use Codeigniter wi...
by kenjis
1 hour ago
Getting supportedLocales ...
by kcs
8 hours ago
Component help
by FlashMaster
Today, 01:41 AM
Show logo in email inbox
by WiParson
Today, 12:48 AM
Limiting Stack Trace Erro...
by byrallier
Yesterday, 02:21 PM
Bug with sessions CI 4.5....
by ALTITUDE_DEV
Yesterday, 01:36 PM
codeigniter 3.0.1 equiped...
by JustJohnQ
Yesterday, 10:05 AM
Display a custom error if...
by b126
Yesterday, 06:22 AM

Forum Statistics
» Members: 85,225
» Latest member: mohdelfie24
» Forum threads: 77,575
» Forum posts: 375,970

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB