Welcome Guest, Not a member yet? Register   Sign In
  Model questions
Posted by: El Forum - 10-14-2008, 02:45 PM - Replies (5)

[eluser]robmcm[/eluser]
Hi,

I have a system similar to an online store.

Currently I have a model for each table in my database, such as order, item, address, user.

I want to create a model for a total order, that has the user, their order, the item and their address (this is theoretical, so please don't ask why Wink ).

Ideally I would create a model for order, that loaded in related tables. Does this sound normal, and does anyone have any examples.

Also I have noticed that most example models return the SQL result set, doesn't it make more sense to return an instance(s) of the model(s) its self, that is built from the query results?

I don't want to break the use of scaffolding, by changing the default methods (although I guess I could create new ones Smile )

Thanks for you help

Rob


  E-mail send with CodeIgniter
Posted by: El Forum - 10-14-2008, 02:32 PM - No Replies

[eluser]Miha Iancu[/eluser]
Hi everybody,

I am not very experienced when talking about CodeIgniter, so I need some help. I am trying to send e-mails with the CodeIgniter E-mail class. When I am sending regular e-mails it works, but if I want an html file as the e-mail's text it won't get the entire content of the file. Is there any rule of how thr html should look like? Mine also has regular paragraph text generated from the database or from a form. Also, if I try to send e-mails with pictures attached, the e-mail received appears to have attachments, but I can't see them in the e-mail. Can anybody explain why is this happening? I don't have any special configurations defined.

Thank you,
Miha


  take out control and view in the url
Posted by: El Forum - 10-14-2008, 02:16 PM - Replies (3)

[eluser]wan19800[/eluser]
does anyone know how to take out control and view in the url structure in codeigniter

ex)
http://www.url.com/control/view/segment3

to

http://www.url.com/segment3


I try .htaccess, it does not work.
any suggestions??


thanks


  Where do you put shared actions between admin and other users?
Posted by: El Forum - 10-14-2008, 12:15 PM - Replies (1)

[eluser]jleequeen[/eluser]
Hello,

I've created an application that has been separated into two sections. I have a public accessible section and then an admin section. My question is where do you put controllers that need to be shared by both? If I have a comments controller for the public, should I also create one for the admin as well? My admin files are in a subfolder. Someone floated the idea that I forget about having a separate folder for admin stuff, that it should all be put in one directory and controlled by ACL. Is this what I should do? I really don't want to have to duplicate controllers if at all possible, but the public app and admin app are really pretty much two different beasts besides maybe 10 shared actions. Any ideas?

Thanks.


  Profiler Memory Usage is misleading
Posted by: El Forum - 10-14-2008, 11:05 AM - No Replies

[eluser]dmorin[/eluser]
The profiler uses mem_get_usage to report memory usage. This function gets the memory usage at the current moment and since the profiler is included at the end of script execution, the number it provides can be very misleading depending on what has been unset, etc.

Using memory_get_peak_usage gives a more accurate figure especially considering this is the kind of number you need to know when running into out of memory errors. Since this is only available in 5.2 and higher it should be in addition to the current function.

~line 346 in Profiler.php could become

Code:
$output .= "<div style='color:#000;font-weight:normal;padding:4px 0 4px 0'>".number_format($usage)." bytes";
if (function_exists('memory_get_peak_usage')) {
    $output .= " ( " . number_format(memory_get_peak_usage()) . " peak bytes )";
}
$output .= "</div>";


  CI Compatible query syntax
Posted by: El Forum - 10-14-2008, 10:50 AM - Replies (2)

[eluser]Computerzworld[/eluser]
Hello, I am having one insert query as,

insert into TABLENAME values(value1,value2,value3,value4,value5).
What is the exact compatible query in CI for this? I don't require the field names in the query.

Thanks in advance.


  Uber-simple login script...
Posted by: El Forum - 10-14-2008, 10:08 AM - Replies (6)

[eluser]Tim Skoch[/eluser]
I wanted a simple way to block all public access to a site except for a few whitelisted controllers. This is what I came up with. I'm using a pre_controller hook. I'd like to use a pre_system hook (because I'm irrationally paranoid :-) ), but I cannot think of a good way to get the routed URI's that early.

Anyway - any thoughts from the community? Criticism? Is this secure? Can I make it even simpler? So far it seems to work great! It also maintains user activity timestamps (for logged-in users only) in session variables, and expires logins automatically.

The hook definition:

Code:
$hook['pre_controller'] = array(
    'class'     =>  '',
    'function'  =>  'startSession',
    'filename'  =>  'login.php',
    'filepath'  =>  'hooks',
    'params'    =>  array()
);

The hook script:
Code:
&lt;?
function startSession() {
    session_start();
    
    $site_url               =   'http://example.com/';
    $loginLength            =   60 * 60;            //  In seconds
    $controllerWhitelist    =   array('view');      //  An array of safe controllers which anyone can access
    $URI                    =&  load_class('URI');  //  Allows us to call the URI class early (since it hasn't been defined yet)
    
    if (!in_array($URI->rsegment(1), $controllerWhitelist)) {
        if (isset($_SESSION['name'])) {
            //  The user is already logged in
            if (    isset(      $_SESSION['lastactivity'])
                 && is_numeric( $_SESSION['lastactivity'])
                 && ((time()-   $_SESSION['lastactivity'])>$loginLength)
                ) {
                dieFcn('Login expired<br /><a href="'.$site_url.'">home</a>');
            }
            $_SESSION['lastactivity'] = time();
        } else {
            $usernameField = 'username';
            $passwordField = 'password';
            if (    isset(  $_POST[$usernameField])
                 && isset(  $_POST[$passwordField])) {
                    //  Credentials were sent, now check them
                    mysql_connect('db_host', 'db_userName', 'db_pw') or die('login error');
                    mysql_select_db('db_dbName') or die('login error');
                    $result = mysql_query("SELECT * FROM users WHERE name='".mysql_real_escape_string($_POST[$usernameField])."' AND pw='".mysql_real_escape_string(md5($_POST[$passwordField]))."'");
                    if (mysql_num_rows($result)==1) {
                        $user=mysql_fetch_assoc($result);
                        $_SESSION['name'] = $user['name'];;
                        $_SESSION['logintime'] = time();
                        $_SESSION['lastactivity'] = time();
                    } else {
                        dieFcn('invalid login<br /><a href="'.$site_url.'">home</a>');
                    }
            } else {
                $dieString = <<<HEREDOC
                    Hey!  Here is some message explaining that users need to
                    log in to view this portion of the site.
                    <br />
                    &lt;form method="post" action=""&gt;
                        <br />&lt;input type="text"        name="$usernameField"/&gt;
                        <br />&lt;input type="password"    name="$passwordField"/&gt;
                        <br />&lt;input type="submit"      value="Login"/&gt;
                    &lt;/form&gt;
HEREDOC;
                dieFcn($dieString);
            }
        }
    }
}

function dieFcn($message='') {
    session_destroy();
    die($message);
}
?&gt;


  Cryptical error message: Undefined property: CI_Loader::$base
Posted by: El Forum - 10-14-2008, 09:33 AM - Replies (1)

[eluser]daveario[/eluser]
Hey there,

I know there are a few topics about “Undefined property: CI_Loader::$base” but none of them can solve my problem.

I wrote a module called “Basement“.

Code:
&lt;?php

if (!defined('BASEPATH')) exit('No direct script access allowed');

class Basement extends Model {

function Basement()
{
    parent::Model();
}

function page_title()
{
    $query = $this->db->query(page_query($this->uri->segment(3)));
    if($query->result() > 0) {
        $row = $query->row();
        echo $row->title;
    }
}

}

?&gt;

In my “header” view, loaded by the “page” view, I loaded the model.
Code:
$this->load->model('basement', 'base', 'TRUE');

Now I want to access the functions.
Code:
&lt;?=$this->base->page_title()?&gt;

but it won't work, I get the following error message:
$this->load->model('basement', 'base', 'TRUE');
Quote:Undefined property: CI_Loader::$base

Can someone help me please? I really don't know why it doesn't work.


  [solved] Rewrite redirect() generates backslash on IIS - Please help
Posted by: El Forum - 10-14-2008, 09:32 AM - Replies (2)

[eluser]Velin[/eluser]
Hi there,

I'm working on my second project in Codeigniter, and it's with great grief and horror that I have to publish this site on an IIS server.

In order to preserve my .htaccess rewrite functionality in my Codeigniter project, I have installed ISAPI Rewrite 3.0 on the IIS box to host the CI site.
My .htaccess file is copied directly from my Apache dev server, and it works flawlessly on IIS using ISAPI Rewrite, for just about everything.
So far ISAPI Rewrite 3.0 looks like a good piece of software.


However, when I attempt to use the redirect() function on my IIS box it redirects to a URL containing a backslash. - This does not happen on Apache, using exactly the same config.

While I realise that this is a probably an IIS/Rewrite problem, and probably doesn't have anything to do with CI, I was hoping one of you have encountered a similar problem.


Example:

On Apache: http://site.dev/login redirects correctly to http://site.dev/login/go
On IIS using the same rewrite conditions, the url redirects to http://site.dev\/login/go



My login controller looks as follows (not surprising):
---
function index()
{
redirect('login/go');
}
---


My .htaccess file:
---
RewriteEngine on
RewriteCond $1 !^(index\.php|img|css|js|robots\.txt)
RewriteRule ^(.*)$ \/index.php/$1 [L]
---


Any help or advise would be greatly apreciated, thanks.


  404 'url fom/index' not found on server error
Posted by: El Forum - 10-14-2008, 09:17 AM - No Replies

[eluser]fourcs[/eluser]
I keep getting this 404 error. Can't find the reason.
This is a snippet of the form_view file.

Code:
<h3 class='headerstyle'>Registration Form</h3>
<p>Please complete the following form:</p>

&lt;?php echo $this->validation->error_string; ?&gt;
&lt;?php echo form_open('form/index'); ?&gt;

  <p><label for="username">Username: </label><br />&lt;?php echo form_input($username); ?&gt;</p>
  <p><label for="password">Password: </label><br />&lt;?php echo form_input($password); ?&gt;</p>
  <p><label for="name">Name: </label><br />&lt;?php echo form_input($name); ?&gt;</p>
  <p><label for="address">Address: </label><br />&lt;?php echo form_input($address); ?&gt;</p>
  <p><label for="city">City: </label><br />&lt;?php echo form_input($city); ?&gt;</p>
  <p><label for="state">State: </label><br />&lt;?php echo form_input($state); ?&gt;</p>
  <p><label for="zipcode">Zipcode: </label><br />&lt;?php echo form_input($zipcode); ?&gt;</p>
  <p><label for="phone">Phone: </label><br />&lt;?php echo form_input($phone); ?&gt;</p>
  <p><label for="email">Email: </label><br />&lt;?php echo form_input($email); ?&gt;</p>
  <p><label for="url">URL: </label><br />&lt;?php echo form_input($url); ?&gt;</p>
  <p><label for="status">Status: </label><br />&lt;?php echo form_input($status); ?&gt;</p>
  <p><label for="dateB">Date Start: </label><br />&lt;?php echo form_input($dateB); ?&gt;</p>
  <p><label for="dateE">Date End: </label><br />&lt;?php echo form_input($dateE); ?&gt;</p>
  
&lt;?php echo form_submit('submit', 'Submit'); ?&gt;
&lt;?php echo form_close(); ?&gt;

I've successfully used similar code and codeigniter config, model, controller, view with a tutorial.
Any ideas will be appreciated.


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

Username
  

Password
  





Latest Threads
Codeigniter Shield Bannin...
by kenjis
9 minutes ago
SQL server connection not...
by kenjis
31 minutes ago
Best way to create micros...
by kenjis
2 hours ago
How to use Codeigniter wi...
by kenjis
2 hours 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
CI 4.5.1 CSRF - The actio...
by jackvaughn03
Yesterday, 10:17 PM
Limiting Stack Trace Erro...
by byrallier
Yesterday, 02:21 PM
Bug with sessions CI 4.5....
by ALTITUDE_DEV
Yesterday, 01:36 PM

Forum Statistics
» Members: 85,226
» Latest member: dewi188
» Forum threads: 77,577
» Forum posts: 375,977

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB