Welcome Guest, Not a member yet? Register   Sign In
  Hook generates whitespace
Posted by: El Forum - 06-03-2008, 06:43 AM - No Replies

[eluser]dioony[/eluser]
Hi there!

I have a problem with my hook. If the hook is enabled, the hook creates a whitespace at the beginning of each page. Normally this is not a problem... But with RSS there is a problem, because XML (thus rss) expects the xml-expression at the first character...

Normally the output should generate "<?xml version=...".
If hooks are enabled it generates " <?xml version=...".

My Hook:

Code:
class TitleHook
{

    function doTitleHook()
    {
        $CI =& get_instance();
        $output = $CI->output->get_output();                    
        
        if(isset($CI->main_title)){
            $title = "WildeWetten - ".$CI->main_title;            
        }else{
            $title = "Normal Title";
        }
        $output = str_replace("{{MAIN_TITLE}}",$title, $output);
        
        $CI->output->_display($output);
        
    }
}

in hooks-config:

Code:
$hook['display_override'][] = array('class'    => 'TitleHook',
                                    'function' => 'doTitleHook',
                                    'filename' => 'TitleHook.php',
                                    'filepath' => 'hooks'
                                   );

i also tested something like
Code:
$output = substr($output,1)
, but it seems, that the whitespace will be added after the hook...

Does anybody know how to fix?


  Help! Error saving to DB when different fields share equal data [RESOLVED]
Posted by: El Forum - 06-03-2008, 05:52 AM - Replies (2)

[eluser]JoostV[/eluser]
Hi,

I use active record for updating data. Works like a breeze, except when two fields in my set() array have the same value. In that case only the first of the two fields is updated. Can anybody help me out here? Am I doing something utterly stupid?

Code example failure
The field 'cat_active' will NOT be updated, because it has the same value as 'cat_catset_id'

Code:
$array = array('cat_catset_id' => '1','cat_title' => 'News','cat_active' => '1');
$this->db->set($array);
Above code will produce this query:
UPDATE `pa_categories` SET `cat_catset_id` = '1', `cat_title` = 'News' WHERE `cat_id` = 1

Code example success
However, if I appoint different data to 'cat_active' and 'cat_catset_id', both fields are updated just fine!
Code:
$array = array('cat_catset_id' => '1','cat_title' => 'News','cat_active' => '0');
$this->db->set($array);
Above code will produce this query:
UPDATE `pa_categories` SET `cat_catset_id` = '1', `cat_title` = 'News', `cat_active` = '0' WHERE `cat_id` = 1

It is driving me crazy! Can anybody explain what is happening here?


  Bug? in Database Library
Posted by: El Forum - 06-03-2008, 05:22 AM - Replies (5)

[eluser]ifew[/eluser]
first i use

Code:
$this->db->where('id', $id);
$this->db->where('metaname', $type);
$query = $this->db->get('tag');
and run. it show "could not connection" in page and other.
if i delete last record in tag table. it ok!?!?!

and now i use standard code with
Code:
$query = $this->db->query("SELECT * FROM tag WHERE id='".$id."' AND metaname='".$type."'");
$row = $query->row();
it's ok.

i use
codeigniter 1.6.2 (library url,input,validation,database)
windows xp pro sp2
apache 2.2.4
mysql 5.0.18
php 5.2.3


  Default controller problem with controller in a subfolder
Posted by: El Forum - 06-03-2008, 04:19 AM - Replies (3)

[eluser]Macros[/eluser]
This seems to have been mentioned before, but still seems to be a bug 1.6.2.

Basically, if the default controller looks like:

Code:
$route['default_controller'] = "folder/controller";

Then the class file is loaded... but the class can't be found.

CodeIgniter.php:
Code:
Line 154: include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
Line 169: $class  = $RTR->fetch_class();

Using the route above, then
Code:
$class = 'folder/controller'
Code:
Line 173: if ( ! class_exists($class)...

This will return false, as the class name being checked is "folder/controller", but the REAL class name is "controller", and it was loaded in the include line.

Cameron.


  Need Help w/ ORM Library
Posted by: El Forum - 06-03-2008, 12:29 AM - Replies (4)

[eluser]Michael Wales[/eluser]
I'm working on my own ORM Library and I can't seem to figure this part out.

First off, here's the library (obviously, not complete):

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed.');

class Orm extends Model {

    var $insert_id;

    function Orm($owners = array()) {
        parent::Model();
    }
    
    // Attempts to save an object (INSERT if no ID is provided, UPDATE if one is)
    function save() {
        // Create an array to save, of only thos values defined in the models setter
        $this->load->helper('date');
        foreach ($this->set as $setter) {
            $save[$setter] = $this->$setter;
        }
        
        // Perform the INSERT/UPDATE as required
        $now = date('Y-m-d h:i:s', now());
        if (!isset($save['id'])) {
            $save['created_on'] = $now;
            $save['updated_on'] = $now;
            $query = $this->db->insert($this->table, $save);
            $this->insert_id = $this->db->insert_id();
        } else {
            $save['updated_on'] = $now;
            $query = $this->db->update($this->table, $save, array('id' => $save['id']));
            $this->insert_id = $this->id;
        }
        
        // Return a useful result to the user
        if ($this->db->affected_rows() == 1) {
            return TRUE;
        }
        return FALSE;
    }
    
    function get_related() {
        if ($this->has_many) {
            $id = substr($this->table, 0, -1) . '_id';
            $var = $this->has_many
            $this->$var = $this->_get_related($this->has_many, array($id => $this->insert_id));
        }
    }
    
    function _get_related($table, $search) {
        $query = $this->db->get_where($table, $search);
        if ($query->num_rows() > 0) {
            return $query->result();
        }
        return FALSE;
    }

}

The issue I am having is within the get_related() method, particularly this line:
Code:
$var = $this->has_many
            $this->$var = $this->_get_related($this->has_many, array($id => $this->insert_id));

Let's take a look at my model - to see exactly what we're trying to accomplish here:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed.');

class Account extends Orm {

    var $table = 'accounts';
    var $has_many = 'users';
    
    var $id;
    var $full_name;
    var $email;
    var $type;
    var $created_on;
    var $updated_on;
    var $set = array('id', 'full_name', 'email', 'type');
    
    function Account() {
        parent::Orm();
    }
}

So, Accounts has_many Users - and the get_related method, should equates to the following (in theory):
Code:
// All in all: $this->db->get_where('users', array('account_id'=>1));
function get_related() {
    if ($this->has_many) {
        $id = substr('accounts', 0, -1) . '_id'; // account_id
        $var = 'users'
        $this->$var = $this->_get_related('users', array('account_id' => $this->insert_id));
        }
    }

If I hardcode the $this->$var portion to $this->users, it works perfectly fine. Obviously, this is not the best solution because it won't work for every possible scenario.

Here's the Controller so you can see the "end developer" code and how I would like this to function.

Code:
function index() {
        $this->load->model('account');
        $a = new Account();
        $a->full_name = 'Michael Wales';
        $a->email = '[email protected]';
        $a->type = 'gold';
        if ($a->save()) {
            $this->load->model('user');
            $u = new User();
            $u->account_id = 1;
            $u->email = '[email protected]';
            $u->password = 'wizard';
            $u->salt = 'aks9di';
            $u->save();
            
            $u = new User();
            $u->account_id = 1;
            $u->email = '[email protected]';
            $u->password = 'wizard';
            $u->salt = 'asksd';
            $u->save();
            
            $a->get_related();
            foreach ($a->users as $user) {
                echo 'Email: ' . $user->email;
            }
        } else {
            echo 'Account not saved.';
        }
    }

Any ideas? The error I get is:
Quote:Parse error: syntax error, unexpected T_VARIABLE in E:\xampplite\htdocs\tiara\libraries\MY_Model.php on line 43


  Confusion re loops for database results
Posted by: El Forum - 06-02-2008, 10:06 PM - Replies (2)

[eluser]jacobkball[/eluser]
Hi there,

A CI newbie question follows Smile

I have a page where I want to list a series of db query results, but I'm having trouble getting my head around how to actually achieve it using models, controllers and views.

What I'm trying to get is:

Category One
- Cat One SubCat One (count of items in subcat)
- Cat One SubCat Two (count of items in subcat)
- Cat One SubCat Three (count of items in subcat)

Category Two
- Cat Two SubCat One (count of items in subcat)
- Cat Two SubCat Two (count of items in subcat)
- Cat Two SubCat Three (count of items in subcat)

and I have these three functions in my model:

Code:
function get_maincat_info () {
    $query = $this->db->get('maincategories');
    return $query->result();
  }
  
  function get_subcat_info ($maincatid) {
    $query = $this->db->where('MainCatID',$maincatid);
    $query = $this->db->get('subcategories');
    return $query->result();
  }
  
  function get_item_count ($subcatid) {
    $query = $this->db->where('SubCatID',$subcatid);
    $query = $this->db->where('ShowItem','y');
    $count = $this->db->count_all_results('iteminfo');
    return $count;
  }

Obviously, a loop is needed in my view:

Code:
<?php foreach ($results as $row) { ?>
       &lt;?php echo $row->MainCatName;?&gt;<br>
    &lt;?php foreach ($subcatresults as $subcatrow) { ?&gt;
        <a href="/search/&lt;?php echo $row->MainCatLink . '/' . $subcatrow->SubCatLink; ?&gt;/" class="catlink">&lt;?php echo $subcatrow->SubCatName; ?&gt;</a>&nbsp;&nbsp;[ &lt;?php echo $countresults[0]; ?&gt; ]<br>
        &lt;?php
        }
    }
?&gt;

but I don't know how to do it so that it loops through each main category, retrieves the sub category info AND count, and returns it to the view.

I don't think I've explained it very well, so let me know what other info you need to see what I'm actually trying to do!!

Hope someone can help Smile

Cheers
Jacob


  Ignited Drupal
Posted by: El Forum - 06-02-2008, 08:17 PM - Replies (6)

[eluser]Jeffrey04[/eluser]
This is roughly how I manage to integrate my drupal 5.7 installation and CI..... requires a bit of hacking that I have no idea whether I am doing things correctly. So use this at your own risk

1. First create a folder named 'ignited_drupal' in your sites/all/modules.
2. Then paste the following files into the folder.
3. Put your application folder and index.php into the folder and place your system folder elsewhere
4. Remember to config your index.php and config.php

ignited_drupal.info

Code:
; $Id$
name = "Ignited Drupal Project"
description = "Integration of Code Ignited PHP framework and Drupal"
package = _CodeIgniter


ignited_drupal.module
Code:
&lt;?php

    define('IGNITED_DRUPAL_TRIGGER', 'app');

    /**
     *  Ignited Drupal help topics
     */
    function ignited_drupal_help($path) {
        $help_text = '';

        switch($path) {
            case 'admin/help#ignited_drupal':
                $help_text = t('Ignited Drupal is a module to integrate
                    <a href="http://www.codeigniter.com/">CodeIgniter</a>
                    and <a href="http://www.drupal.org">Drupal</a>.');
                break;
        }

        return $help_text;
    }

    /**
     *  To set the permission to access the ignited_drupal installation
     *  root page
     */
    function ignited_drupal_perm() {
        return array(
            // define whether one can access to the root
            'access ignited_drupal root'
        );
    }

    /**
     *  To set the menu items
     */
    function ignited_drupal_menu() {
        $items = array();

        // the root of the installation
        $items[] = array(
            'path' => IGNITED_DRUPAL_TRIGGER,
            'title' => t('Additional applications'),
            'callback' => 'ignited_drupal_start_app',
            'access' => user_access('access ignited_drupal root'),
            'type' => MENU_CALLBACK
        );

        return $items;
    }

    /**
     *  Start the codeigniter application
     */
    function ignited_drupal_start_app() {
        ob_start();
        _ignited_drupal_process_request($_GET['q']);
        require dirname(__FILE__) . '/index.php';
        $output = ob_get_contents();
        ob_end_clean();
        return $output;
    }

    /**
     *  Theme the codeigniter application
     */
    function theme_ignited_drupal($content) {
        print theme('page', $content);
    }

    /**
     *  Process the request into codeigniter understandable format
     */
    function _ignited_drupal_process_request($query) {
        // take out the first portion of query
        $start_length = strlen(IGNITED_DRUPAL_TRIGGER . '/');
        
        if(strpos($query, IGNITED_DRUPAL_TRIGGER . '/') !== FALSE) {
            $query = substr($query, $start_length);
        } else {
            $query = '';
        }
        
        $_SERVER['PATH_INFO'] = $query;
    }

    /**
     *  Populate the $_GET array to enable codeigniter to redirect
     *  request
     */
    function _ignited_drupal_set_param($param, $index, $key) {
        if(isset($param[$index])) {
            $_GET[$key] = $param[$index];
        }
    }

Activate the drupal module, and then you can access your CI application using the address ?q=app/<controller>/<method>

However, you will probably get some error messages from PHP that CI system files are calling methods from non-object.
For example in the system/libraries/Output.php
Code:
global $BM, $CFG;   // this would return null object
        $BM =& load_class('Benchmark'); // so I load the object using &load;_class
        $CFG =& load_class('Config');

I have also did the similar hack to some other system files.

I am not sure whether this hack is appropriate, please comment Tongue


  CachedObjects v1.2 - cache granularity as you want
Posted by: El Forum - 06-02-2008, 08:16 PM - Replies (16)

[eluser]sdbruder[/eluser]
CachedObjects v1.2
cache granularity as you want

CachedObjects is a core extension (MY_Controller and MY_Model extensions) that implements caching at method level at call time.

Apart from extending the MY_ versions, all that you need to do is:
* Declare the time to cache calling methodcache(time_in_minutes);
* call ->mymethodCached(parameters) to cache ->mymethod(parameters);
* WARNING: CachedObjects will use object name, method name and parameter values to hash the cache name. If your method can accept a multitude of diferent values as parameters, you will get a multitude of cache entries. USE IT WISELY!

TODO
* The cache code is replicated in MY_Controller and MY_Model extensions, the bulk of it can be
extracted to a single place to avoid code replication.

In the package, there is a model / view / controller as an example, Open it in your applicaction directory and call http://yourserver/index.php/examplepage/. If you use it in your project, please send an email.

Download: http://sergio.bruder.com.br/cachedobjects/


  How do you reset an object
Posted by: El Forum - 06-02-2008, 04:50 PM - Replies (4)

[eluser]floweringmind88[/eluser]
I loaded a class from my library. It works great but then the second time I call the object function it spits out the old data instead of the new data.

Is there a way to reset the class object?

Thanks!
Chris


  Have to refresh pages to view current data
Posted by: El Forum - 06-02-2008, 04:18 PM - No Replies

[eluser]Dave S[/eluser]
I'm creating a simple website where members can log in. If they are logged in, the header displays different data than it would to someone who is not logged in.

I have finally been able to get this all working with one exception. I will try to explain the problem by using an example.

If the person enters their login information and submits they are taken to http://site.com/login. The login controller validates the info and if successful, displays a view telling the user they are logged in.

Here is the problem. If the user then goes back to http://site.com/ (or any other page) by typing the url in the browser, they still get the header with the login fields, and have to hit refresh to see the "welcome" info that logged in users should see. However, if they click the "home" link from the view telling them they are logged in, everything is fine.

The same thing happens when they log out. They get a view telling them they're logged out. If they type in any url on the site they still see the logged in header unless they hit refresh.

I hope that makes sense. Does anyone have any ideas on what might be going on? I have the code to check if the user is logged in right in the constructor for any of the controllers that require it.

Thanks in advance!


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

Username
  

Password
  





Latest Threads
TWIG
by foxbille
2 hours ago
Codeigniter4 How i can co...
by demyr
2 hours ago
v4.4.7 Security Fix relea...
by InsiteFX
7 hours ago
Do not use the CI 4 sessi...
by joho
Yesterday, 04:58 PM
Codeigniter 4 Model set()...
by kenjis
Yesterday, 04:07 AM
CI Builder Question
by InsiteFX
03-27-2024, 10:56 PM
SecurityException Status ...
by kenjis
03-27-2024, 03:50 PM
E-mail and UTF-8, mb_, et...
by joho
03-27-2024, 07:13 AM
Shield validation questio...
by Codinglander
03-27-2024, 07:07 AM
CI4 support MariaDB?
by joho
03-27-2024, 07:06 AM

Forum Statistics
» Members: 82,334
» Latest member: vn123page
» Forum threads: 77,482
» Forum posts: 375,543

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB