Welcome Guest, Not a member yet? Register   Sign In
  Documentation typo - Image Lib
Posted by: El Forum - 07-07-2008, 01:12 AM - Replies (2)

[eluser]coolfactor[/eluser]

Quote:wm_vrt_offset
You may specify a vertical offset (in pixels) to apply to the watermark position. The offset normally moves the watermark to the right, except if you have your alignment set to "right" then your offset value will move the watermark toward the left of the image.
wm_hor_offset
You may specify a horizontal offset (in pixels) to apply to the watermark position. The offset normally moves the watermark down, except if you have your alignment set to "bottom" then your offset value will move the watermark toward the top of the image.

Image Lib docs here

These seem to be switched around. The "vertical" offset makes reference to left and right, whereas the "horizontal" offset makes reference to top and bottom.

Am I reading it wrong?


  newbie class constructor question on the PHP 4 vs PHP 5 syntax
Posted by: El Forum - 07-07-2008, 12:19 AM - Replies (2)

[eluser]Doug Lerner[/eluser]
In the documentation it points out that this syntax is used to define a construction in PHP 4:

Code:
class Blog extends Controller {

       function Blog()
       {
            parent::Controller();
       }
}

while this syntax is used in PHP 5:

Code:
class Blog extends Controller {

       function _construct()
       {
            parent::Controller();
       }
}

In the rest of the documentation pages the PHP 4 syntax seems to be used.

My question is, if my site is using PHP 5 does it make any difference at all which syntax I actually use, or are they equivalent in PHP 5?

Thanks,

doug


  Sessions question
Posted by: El Forum - 07-06-2008, 11:21 PM - Replies (9)

[eluser]jinit13[/eluser]
I'm trying to implement a simple login system, however, I followed CI user guide on sessions library and i can't get it work
The login method on users controller

Code:
function login(){
            $rules['name']    = "trim|required";
            $rules['password']    = "trim|required|md5";

            $this->validation->set_rules($rules);
            if ($this->validation->run()==FALSE){
                $this->load->view("users_login");

            }else{
                $name=$this->input->post('name');
                $password=$this->input->post('password');
                if($this->User_model->user_exists($name, $password)){
                    //Login code..
                        $sess_data = array(
                            "logged_in"        =>    TRUE,
                            "name"    =>    $name);
                        $this->session->set_userdata($sess_data);

                        $this->load->view('users_index');
                }


            }

users_login view:
Code:
<html>
    <head>
        <title>
            Login
        </title>
    </head>
    <body>
        &lt;?=form_open('users/login')?&gt;<br/ >
        &lt;?=form_fieldset('Login')?&gt;
        &lt;?php
        if($this->validation->error_string) {
            echo $this->validation->error_string . "<br />";
        }?&gt;

              <table>
                <tr>
                  <td>Name:</td><td>&lt;?=form_input('name', '')?&gt;</td>
                </tr>
                <tr>
                  <td>Password:</td><td>&lt;?=form_password('password', '')?&gt;</td>
                </tr>
                  <td>&lt;?=form_submit('btnsubmit', 'Login!')?&gt;</td><td></td>
                </tr>
              </table>

        &lt;?=form_fieldset_close()?&gt;
        &lt;?=form_close()?&gt;
    &lt;/body&gt;

&lt;/html&gt;

users_index view:
Code:
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;Users&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
    <table>
        <th>Users</th>


        &lt;?php foreach($q->result() as $row):?&gt;
            <tr>
                <td>&lt;?=$row->name?&gt;</td>
            </tr>
        &lt;?php endforeach;?&gt;


    </table>


      <hr width="100!"! size="2">


    &lt;?php
        if ($this->session->userdata("logged_in"==TRUE)){
            echo("Logged in as ". $this->session->userdata("name"));
        }else{
            echo "Unknown!";
        }
    ?&gt;

    &lt;/body&gt;


&lt;/html&gt;
This part exactly is what I'm looking for
Code:
if ($this->session->userdata("logged_in")==TRUE){
            echo("Logged in as ". $this->session->userdata("name"));
        }else{
            echo "Unknown!";
        }
Thanks in advance


  Database bug for form_submit?
Posted by: El Forum - 07-06-2008, 10:12 PM - Replies (5)

[eluser]Unknown[/eluser]
If you try to use the form_submit helper function and then insert the data into a database from the $_POST data, the Database class will try to insert data into a column with the same name as the submit input button, which most likely will not exist.

For example, suppose you want to add a blog comment to the blog_comments table.

Suppose that in your comment_add.php view your have:

echo form_submit('submit', 'Add Comment');

and in your comment_add() function in your blog controller, you have

$this->db->insert('blog_comments', $_POST)

and that you do not have a column named 'submit' in your blog_comments table of your database,

then you will get an insert error that says it cannot find the column named 'submit'

To fix this, we may want to have the insert function of the Database class check the type of the input, and if it is of type submit or reset, then it should not treat it as a column name.

This seems to be a bug for the Database class. Am I correct?


  Pagination class and Search Function help!
Posted by: El Forum - 07-06-2008, 10:00 PM - Replies (4)

[eluser]Devon Lambert[/eluser]
I've been at this one for a few hours now and thought it couldn't hurt to hit up the CI community for some much needed Ninja Style assistance.

Here's the deal:

I've created a quick and dirty CI search function and have made use of it in my controller and view. I've whipped up a table with a little bit of css styling that is calling in my search results. I do not want to break this setup and I do not want to shift any view code into my controller or model, besides, that wouldn't be the right MVC thing to do would it?

The main issue is that when I click on my 2nd paginated link, I receive the following error:

Code:
Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: search.php

Line Number: 14

Here is the code I have so far:

CONTROLLER:

Code:
&lt;?php

class search extends Controller {

    function search()
    {
            parent::Controller();
        $this->load->model('mdl_search');
    }


    function index()
    {
        $data['title'] = "Better Search";
        $keyword = $this->input->xss_clean($this->input->post('keyword'));
            $data['count_results'] = $this->mdl_search->countResults($keyword);
        $this->load->library('pagination');

        $config['base_url'] = base_url().'search/index';

        $config['total_rows'] = $data['count_results'];

        $config['uri_segment'] = '2';

        $config['per_page'] = '10';

        $this->pagination->initialize($config);

             $offset = $this->uri->segment(3);

        $data['search_results'] = $this->mdl_search->getSearchResults($keyword, $config['per_page'], $offset);                

        $this->load->view('search', $data);
    }
}
?&gt;

MODEL:

Code:
&lt;?php

class mdl_search extends Model {



    function mdl_search()

    {

        parent::Model();

    }




    function getSearchResults ($keyword, $limit, $offset)

    {

        $keyword = trim($keyword);



        if($keyword != ''){



            $this->db->like('name', $keyword);

            $this->db->or_like('desc', $keyword);

            $this->db->or_like('cat', $keyword);

            $this->db->or_like('instructions', $keyword);

            $this->db->orderby('name', 'ASC');

            $result = $this->db->get('games',  $limit, $offset);

            $output = $result->result_array();

            return $output;

        }

        

        else {return 0; }

    }

    

    function countResults ($keyword){

        

        $keyword = trim($keyword);



        $this->db->like('name', $keyword);

        $this->db->or_like('desc', $keyword);

        $this->db->or_like('cat', $keyword);

        $this->db->or_like('instructions', $keyword);

        $this->db->orderby('name', 'ASC');

        $this->db->from('games');

        $query = $this->db->count_all_results();

        

        return $query;

    }

}

?&gt;

VIEW:

Code:
<div class="search-container">

        <h2>&lt;?= $title;?&gt;</h2>

        <div class="pagination">&lt;?php echo $this->pagination->create_links(); ?&gt;</div>

        
<table class="search-results">

                <tr>

                    <th><a href="#"><span>Game Title</span></a></th>

                    <th><a href="#"><span>Players</span></a></th>

                    <th><a href="#"><span>Rating</span></a></th>

                    <th><a href="#"><span>Reviews</span></a></th>

                    <th><a href="#"><span>Play Type</span></a></th>

                </tr>

                

                    &lt;? foreach ($search_results as $search_result): ?&gt;

                        <tr>

                            <td><a href="#">&lt;?php echo $search_result['name'];?&gt;</a><br />&lt;?php echo $search_result['desc'];?&gt;</td>

                            <td>1,262</td>

                            <td><b>5.00</b><br />out of 5.0</td>

                            <td><span class="up">72%</span><br />491 reviews</td>

                            <td></td>

                        </tr>

                    &lt;? endforeach; ?&gt;

        </table>

    </div>

So far, I can get the search function to work just fine, but when I combine this with the pagination and go to any other page besides the first search page, it's as if the post data I went searching for gets thrown out.

Please, any help is definitely appreciated in getting this working. :-)


  Problem in Creating Two Instances of Flexigrid
Posted by: El Forum - 07-06-2008, 09:34 PM - No Replies

[eluser]Unknown[/eluser]
Hi All,

I'm using two instances of FlexiGrid in a page and I'm encountering the
below error on the pagination stat:

Page of [object Object]

What do you think causes the error? By the way this error appears only
on FF. It is not displaying on IE but still there is an error (records
don't appear).

Any idea?

Thanks,
Nimrod


  A simple newbie question about installation and multiple apps
Posted by: El Forum - 07-06-2008, 09:01 PM - Replies (9)

[eluser]Doug Lerner[/eluser]
This is a very newbie question.

In the install instructions it says:


Unzip the package.
Upload the CodeIgniter folders and files to your server. Normally the index.php file will be at your root.
Open the application/config/config.php file with a text editor and set your base URL. If you intend to use encryption or sessions, set your encryption key.
If you intend to use a database, open the application/config/database.php file with a text editor and set your database settings.

My questions are,

(1) Where should you put the files if you intend to develop multiple applications?

(2) Is the set of folders and files supposed to be duplicated for each application?

(3) A site will normally already have an index.html. Do you really want index.php at the root of the site even if an index.html already exists there?

Thanks,

doug


  Checkboxes
Posted by: El Forum - 07-06-2008, 08:52 PM - Replies (8)

[eluser]stuffradio[/eluser]
What method do you use for check boxes? I just want them to have a value of true and false. If it's checked when the form is submitted, it'll say true in the database, if not it will be false.


  Functional PHP Extension
Posted by: El Forum - 07-06-2008, 08:30 PM - Replies (20)

[eluser]Jamongkad[/eluser]
Functional PHP Extension

I all it's been a while since my last contribution to this community. But I feel that CI has given us so much in terms of developer happiness. It actually made me appreciate PHP again. Anyways here again is my small contribution to the community.

Just a few months ago I started to appreciate the power and expressiveness of Functional Programming, my work in using languages such as Scheme has opened my mind to new paradigms. I wanted to know if languages such as PHP can atleast scratch the surface of the power of FP.

Unfortunately in order to do anything remotely related to FP the language must support higer order functions(functions as first class citizens) which PHP does not. Lexical Scoping(which PHP does not execute as elegantly as other languages). These and a lot more are required, thus we come to the this humble library. Please note this library is more of a supplement and a helper to your code. I know it helped me a whole and I hope it does the same for you.

I'm currently the maintainer and active contributor to this library and I would like to share with the community the possiblity of writing code in a more functional manner and practicing Paul Graham's theory on power

So without further ado I'm pretty amped to demonstrate the power of this library with a few examples.
In order to load this library one must simple place it in their helpers folder. Change the file name to functional_helper.php and simply autoload it.

Anonymous Functions
The main crux of this library and the reason why I use it. One would want to utilize the power of unnamed functions for tasks that do not generally require the use of named functions. Small throw away tasks that one can utilize.

In order to invoke the use of anonymous functions...now I know some of you might be thinking that PHP has create_function. And I'm here to tell you that in the true spirit of FP anonymous functions immediately return their expressions. Create_function in all it's awkwardness defines it's expressions procedurally.

Here I define two lamdba functions.

Code:
$plus5 = lam('$x','$x + 5');
$times2 = lam('$x','$x * 2');

$combine = $plus5($times2(7));
//the result will be 19
Awesome isn't it? The library is well commented and you can find more examples I cooked up.

Scheme like Begin
This function was borrowed from Scheme and it allows the one to invoke functions by sequence. The function was inspired by the work of Dikini.net and his contributions.

Code:
function say() {
   echo "My";
}

function my() {
   echo " name ";
}

function name() {
   echo " is Mathew Wong.";
}

echo begin(
        say(),
        my(),
        name()
      );

//which would yield "My name is Mathew Wong."

Concat is the missing array reduction operation in PHP. It's closely related to implode.
Code:
$arr = array(
         'My name is Mathew Wong',
         'Ian Kjos is the original author of the Functional PHP library',
         'This is his implementation',
         'I love Functional programming!'
        );
echo concat($arr,'<br/>');
//Which will result....
    My name is Mathew Wong
    Ian Kjos is the original author of the Functional PHP library
    This is his.....
    I love Functional....

These trivial examples obviously do not do the library and it's original author justice. But for the sake of brevity I wanted to show you guys a taste of the expressive power that is contained in this library. There are alot more functions and combinators in the library that if I were to list them all one page would not be enough for this post.

Thank you and if there any questions I'll be more than happy to entertain them.


  Use the codeigniter library in hook class or function,HOWTO
Posted by: El Forum - 07-06-2008, 08:15 PM - Replies (2)

[eluser]Unknown[/eluser]
Hi all:
How use the codeigniter library in hook class or function, such as database class.
Hook Point: pre_controller.
Tks.


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

Username
  

Password
  





Latest Threads
Coverting a CI3 Project t...
by Josh1985
5 minutes ago
File not found on my onli...
by Kobbs
2 hours ago
CodeIgniter4 - How i can ...
by kenjis
2 hours ago
Can't read a session
by ElTomTom
6 hours ago
Validation error messages...
by ozornick
10 hours ago
How to Find & Hire Codeig...
by Bosborne
Today, 03:09 AM
Insert in joint table bef...
by kcs
Today, 01:20 AM
I built 30 startups in 20...
by InsiteFX
Yesterday, 11:07 PM
6 hard truths about learn...
by InsiteFX
Yesterday, 11:04 PM
4.4.1 to 4.4.8 base_url p...
by kenjis
Yesterday, 04:02 PM

Forum Statistics
» Members: 87,134
» Latest member: King33page
» Forum threads: 77,633
» Forum posts: 376,305

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB