Welcome Guest, Not a member yet? Register   Sign In
  Problem extracting correct information from database
Posted by: El Forum - 03-30-2008, 07:21 PM - Replies (3)

[eluser]jbads[/eluser]
Hi, I am developing a function/page controller that would like to take a parameter from the url and use that parameter (in this case username) to extract data to populate a profile for the user.

Overall, the controller is in it's infancy, and I'm learning codeigniter as I go, therefore only the basic operations have been coded.

When I load this function through the browser eg. localhost/site/index.php/class/function/parameter it is only extracting the last row in the database, not the row specified in the url. If I enter a url with no /parameter/ it still returns the last entry in the database.

Here is my function thus far, could you please advise me what is wrong with my sql

Quote: function viewprofile(){
//retrieve username from URL
$url_username = $this->uri->segment(3);


if(!isset($url_username)){

redirect('core');

}

$data['segment_id'] = $url_username;

//get info from database
//build where clause in sql statement
$where = $this->db->where('username', $url_username);



//run query
$query = $this->db->query('SELECT * FROM table $where;');

$data['segment_id'] = $query->num_rows();



//check that there was a result
if ($query->num_rows() > 0){
//put results into usable variables
foreach($query->result_array() as $row){
$data['username'] = $row['username'];
$data['firstname'] = $row['firstname'];
$data['lastname'] = $row['lastname'];
$data['emailaddress'] = $row['emailaddress'];
}

}else{
redirect('core');
}


$page_header['title'] = "View Profile";

$this->load->view('index_header_view', $page_header);
$this->load->view('index_menu_view');
$this->load->view('profile/view_profile_body_view', $data);
$this->load->view('index_footer_view');

}


Any other advise in regards to this code would be greatly appreciated,
Thanks, Jake


  Pre-populated form with validation class
Posted by: El Forum - 03-30-2008, 06:05 PM - Replies (3)

[eluser]Unknown[/eluser]
Hi,

I have an "edit" page for a form and am using the validation class, but can't figure out how to display the initial value retrieved from the database. If I have to assign the value of the validation to the input, what's a good way to pre-populate the field with the initial value?

view:

Code:
echo form_input('name', $this->validation->name);

controller:
Code:
public function edit() {

    $this->load->model('Company_model');
    $this->load->library('validation');

    $vrules['id'] = 'required';
    $vrules['name'] = 'trim|required';
    $this->validation->set_rules($vrules);

    $vfields['id'] = 'ID';
    $vfields['name'] = 'Name';
    $this->validation->set_fields($vfields);

    if($this->validation->run()) {

        // update db and do stuff
    
    } else {

        $id = $this->uri->segment(3);
        $data['query'] = $this->Company_model->get_single($id);

        // display form
        $this->load->view('header', $data);
        $this->load->view('company/edit');
        $this->load->view('footer');

    }
}


  Pagebreak
Posted by: El Forum - 03-30-2008, 05:15 PM - Replies (3)

[eluser]Kemik[/eluser]
Hello all,

I'm coding a blog backend and want the homepage to only display the content up to the point where it finds a <!-- pagebreak --> You may recognise the comment, it's from a TinyMCE pagebreak.

I know how to find a string in content but I'm not sure how to make it stop when it finds it.

e.g.

Quote:Here is some text.

Blah Blah Blah
<!-- pagebreak -->
And some more

You wouldn't see "And some more".

Thanks.


  An alternative way to send variables to functions?
Posted by: El Forum - 03-30-2008, 02:45 PM - Replies (19)

[eluser]KeyStroke[/eluser]
I read in the guide that you can send variables this way:
http://example.com/controller/variable1/variable2

However, in my case, my variables aren't always all needed at the same time, so I'd rather use something like:
http://example.com/controller/?var1=this&var2=that

because it's more flexible.

Is this possible in CodeIgniter? I just need an alternative that allows me to control variables like that.


Your help is much appreciated Smile


  AE Session : Yet Another Session Library
Posted by: El Forum - 03-30-2008, 02:22 PM - Replies (1)

[eluser]Aea[/eluser]
It feels a little bit awkward releasing yet another session library, especially after another one was posted within the week. This code originates from some Native Session Library modifications I made a few weeks ago, but hadn't thought to release until now. Unlike (some of the) other session libraries, this code is:

- Extremely Lightweight
- Relies on Native $_SESSION variables
- Relies on PHP5 Functions

Offers:
- Protection against Session Fixation
- Efficient Handling of Flash Session Data

AE Session is only compatible with PHP5, however you can drop in Native Session's regeneration function and it should work. I work only with PHP5 thus there was no need to use the round-about PHP4 style session regeneration. This library doesn't do everything, in fact it does very few things (see KNDB Session if you need a powerful Session Library), but it does them very well.

Without further ado:

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

/**
* Session class using native PHP session features and hardened against session fixation.
* Includes handling for Flash Session Data & optimized for PHP5 (session_regenerate_id(TRUE) is not PHP4 Compatible)
*
* @package     CodeIgniter
* @subpackage  Libraries
* @category    Sessions
* @author      Artur Ergashev, Originally Forked from the code of Dariusz Debowczyk's 'Native Session'
*/

class CI_Session {

    function CI_Session()
    {
        $this->object =& get_instance();
        log_message('debug', 'AE_Session Class Initialized');
        $this->_sess_run();
    }

    function destroy()
    {
        unset($_SESSION);
        if ( isset( $_COOKIE[session_name()] ) )
        {
            setcookie(session_name(), '', $_SERVER['REQUEST_TIME']-42000, '/');
        }
        session_destroy();
    }

    function _sess_run()
    {
        session_start();

        if ($this->_session_id_expired())
        {
            session_regenerate_id(TRUE);
            $_SESSION['regenerated'] = $_SERVER['REQUEST_TIME'];
        }
        
        $this->_flash_countdown();
    }
    
    function _flash_countdown()
    {
        $session_keys = array_keys($_SESSION);
        
        foreach ($session_keys as $key)
        {
            $search = $key.':flash';
            if (isset($_SESSION[$search]))
            {
                if ($_SESSION[$search] <= 0)
                {
                    unset($_SESSION[$key], $_SESSION[$search]);
                }
                else
                {
                    --$_SESSION[$search];
                }
            }
        }
    }
    
    function _session_id_expired()
    {
        if (!isset($_SESSION['regenerated']))
        {
            $_SESSION['regenerated'] = $_SERVER['REQUEST_TIME'];
            return false;
        }

        $expiry_time = $_SERVER['REQUEST_TIME'] - $this->object->config->item('sess_expiration');

        if ($_SESSION['regenerated'] <=  $expiry_time)
        {
            return true;
        }

        return false;
    }
}
?&gt;

Installation and Usage
Drop the code named as Session.php into applications/libraries
Edit your config.php...
Code:
$config['sess_expiration']        = 300;

Five minutes seems like a good regeneration interval, you may adjust this based on your requirements. All other session variables are unused, and you may comment them out.

Setting and retrieving session data is done using $_SESSION['key'], you can at any time convert data to flash data and back, here's how this works...

Code:
$_SESSION['my_data'] = ...;
$_SESSION['my_data:flash'] = #

# corresponds to how many pages you want this data to persist. If you want to remove the flash data limit, simply unset the my_data:flash key, and it'll return to being persistent session data.

Enjoy, and feel free to improve on my implementation.


  Newbie: Problem with Geolocater
Posted by: El Forum - 03-30-2008, 12:22 PM - Replies (6)

[eluser]Private Dancer[/eluser]
Hi forums.

I'm very new with CI and i get a problem. I try to use the Geolocater like described here => http://codeigniter.com/wiki/Geo_Locater/

I set up the DB and also the library like the wiki. I then added the following code to my controller:

Code:
$this->load->library('geolocater');
        $data['geo'] = $this->geolocater->getlocation('<myip>', TRUE);
        
        $this->load->view('start_view', $data);

And the following in the view:
Code:
&lt;?php echo $geo;?&gt;

The only output i then have is "Array" with some whitespace. I think i do a mistake in the controller. I probed a lot. But nothing works. Hope you can help. Smile


  How is YOUR CI set up?
Posted by: El Forum - 03-30-2008, 12:04 PM - Replies (2)

[eluser]pgsjoe[/eluser]
I'm beginning development of my second site and one of the things I've been wondering, that I can't seem to find information on is how to have the site set up. So, figured I'd pose the question to all of you out there for some feedback.

Here are the problems I'm encountering.

1) I have an assets folder (containing css, js, flash, etc.), where do I put it? Views folder? Root? Also, how do I link to it?

2) Most sites generally have, what, maybe three different templates. An index and two different interior pages...usually. I feel like I would set up these templates inside of the views folder (views/templateA.php, views/templateB.php, views/templateC.php). But then, where would I store the content for each page. It doesn't need to be inside of a database, so where do I put it? Or, do I load each section of content as a completely different view? Or do I store it as XML.

3) I know I've seen 'em around before, but for thread/search purposes, is there a tried and true way that you've set up your .htaccess to remove the full codeIgniter from the URL structure?

4) Is it recommended, or advised against to set up folders inside of the views folder for different sections of the site. For instance, the one I'm working on now has the main content, then two products.

I guess just all in all, what is the best practice you've found for setting up your own site?


  Trying to iniciate app, getting 500 internal error
Posted by: El Forum - 03-30-2008, 11:52 AM - Replies (4)

[eluser]Rubiz'[/eluser]
Well.. I've installed XAMPP5 in my mac, and now I'm trying start my app dev, but I'm getting 500 internal error... When I installed CI I got the welcome message successfully, than I made:

config changes to http://localhost/app_name
route changes to default controller called main
and made main controller page and main view page.

What's wrong? anyone knows?


  thinking about sessions and databases
Posted by: El Forum - 03-30-2008, 11:09 AM - Replies (9)

[eluser]jbowman[/eluser]
I've been thinking about sessions and databases, and think I might have come up with a solution that will work well for both performance and security reasons.

I'm trying to keep database queries down to a minimum, but I want to have session data that includes information I won't trust coming from a user supplied cookie. I also want the site to have the ability to scale horizontally for the web servers serving it, which means I need to keep the session information in a shared resource, such as a database.

I think the answer is this. User sessions get stored in the database, and cached as a file on the web server. The session process would then work like this..

Check for a session id supplied by the browser.
If the session id does not exist, start a new session.
If the session id does exist, check the local file cache for the session.
If the cache file does not exist, check the database.
If the session exists in the database, create a cache file and continue.
If the session does not exist in the database, then start a new session.

This way if you have multiple web servers, and load balancing has the user move to a different server for some reason (I'd rather not get into the persistence features of NLBs, as web servers themselves can go down), a new cache file is created as the only database request for the session.

Any thoughts or comments? I'm currently using NGSession and may try to add this functionality once I get further into the development of my site, if no one else beats me to it.


  How to check if a view exists
Posted by: El Forum - 03-30-2008, 08:44 AM - Replies (12)

[eluser]mikegioia[/eluser]
I was wondering if it was possible to check if a View exists before loading it. The reason I'm asking is because I have user dashboards where they can load different widgets, and each widget has a View. And while the names of the views match up with the names of the widgets stored in the database, I just wanted to add another level of security there so that the script doesn't terminate with an unable to load view error.

If anyone has any suggestions I'd really appreciate it.


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

Username
  

Password
  





Latest Threads
Bug with sessions CI 4.5....
by ALTITUDE_DEV
1 hour ago
Validation | trim causes ...
by kenjis
3 hours ago
Integrating Bootstrap 5 i...
by Bosborne
4 hours ago
Error / Shield 1.0.3 + Ci...
by kenjis
5 hours ago
Asset Minification Packag...
by tarcisiodev1
Yesterday, 05:11 PM
Modify users data as an a...
by luckmoshy
Yesterday, 04:56 PM
Is it possible to go back...
by ejimenezo
Yesterday, 11:49 AM
SQL server connection not...
by davis.lasis
Yesterday, 07:11 AM
Problem with session hand...
by Julesb
Yesterday, 04:13 AM
External script access to...
by PomaryLinea
Yesterday, 03:58 AM

Forum Statistics
» Members: 85,547
» Latest member: 33winnhacai
» Forum threads: 77,586
» Forum posts: 376,030

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB