Welcome Guest, Not a member yet? Register   Sign In
Calendaring Class???
#1

[eluser]JimmyJ[/eluser]
Hey, i'm very new to cl and i'm going through the documentation.

I really really like it, but i'm stuck at something very simple!!

I'm going through the simple blog tutorial and i can't figure out how to spit out a simple calendar (or any other class for that matter) into my blogview.php page.

Code for blog.php is:

Code:
<?php
class Blog extends Controller {

    function index()
    
    {
        
        $this->output->cache(60);
        
        $data['todo_list'] = array('Clean House', 'Call Mom', 'Run Errands');

        $data['title'] = "My Real Title";
        $data['heading'] = "My Real Heading";
        
        
        $this->load->view('blogview', $data);
        
        
        $this->load->library('calendar');
    }
    
}
?>

And my blogview.php is

Code:
<html>
<head>
<title><?php echo $heading;?></title>
</head>
<body>
<h1>&lt;?php echo $heading;?&gt;</h1>
    
<h3>My Todo List</h3>    

<ul>
&lt;?php foreach($todo_list as $item):?&gt;

<li>&lt;?php echo $item;?&gt;</li>

&lt;?php endforeach;?&gt;
</ul>
    &lt;?php echo $this->calendar->generate(); ?&gt;
&lt;/body&gt;
&lt;/html&gt;

How do i spit out the calendar to the page?
#2

[eluser]Pandabeer[/eluser]
Your view acts as a return statement. Place

$this->load->library('calendar');

above the view load->view function and it should work.
#3

[eluser]JimmyJ[/eluser]
Yeh, that worked. Thankyou Wink
#4

[eluser]oliviermarian[/eluser]
Hi,
I was looking for kind of the same information.
My problem is that the calendar is loaded in first in the view, meaning it appears top of page.

What I do to place it where I want is that I use the personalisation of the calendar template to add <div> settings in the template, so that to calendar is displayer where I want in my view.

$prefs['template'] = '{table_open}<div STYLE="border-style:hidden; position: absolute;top:50px;left:100px"><table border="0" cellpadding="0" cellspacing="0">{/table_open}.....'


It works but the HTML code source of the generate view (the webpage) is awfull as the calendar is generated before the &lt;head&gt; and &lt;body&gt;....

What is the clean way to do this ? how do you manage to insert the calendar in the right place of the view ?

thxs.
olivier.
#5

[eluser]Pandabeer[/eluser]
You are possible using the generate function in the controller instead of the view. You could also generate it and put it in a variable and then give it to view, instead of echo'ing in your controller, which is not really the way to go. It's all up to you.
#6

[eluser]oliviermarian[/eluser]
Hi
Yes i was calling
Code:
$this->calendar->generate($this->uri->segment(3), $this->uri->segment(4), $data);
from the controller.

I tried in the view but it does not work... Are you sure it can be called from the view ?

My view code is:
Code:
&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
    test
<hr>
    &lt;?php
        $prefs = array (
            'show_next_prev'  => TRUE,
            'next_prev_url'   => 'http://www.your-site.com/index.php/calendar/show/'
            );
        $this->load->library('calendar', $prefs);
        $data = array(
               3  => 'http://your-site.com/news/article/2006/03/',
               7  => 'http://your-site.com/news/article/2006/07/',
               13 => 'http://your-site.com/news/article/2006/13/',
               26 => 'http://your-site.com/news/article/2006/26/'
             );
        $this->calendar->generate($this->uri->segment(3), $this->uri->segment(4), $data);
    ?&gt;
&lt;/body&gt;

this generates this error
Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Loader::$calendar
Filename: views/formsucces.php
Line Number: 19
#7

[eluser]Pandabeer[/eluser]
You can load the library in the controller, with the preferences. You need to echo the generate function. Then it should work.
#8

[eluser]oliviermarian[/eluser]
Sorry, you were right; I was noob ;-)
it works now!

for the next noob; here is the code..

in the controler:
Code:
function calendar()
        {
            $this->load->library('calendar');
            $this->load->view('calendar_view');
        }
in the view
Code:
&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
    test
<hr>
&lt;?php
            echo $this->calendar->generate();
?&gt;
&lt;/body&gt;




Theme © iAndrew 2016 - Forum software by © MyBB