Welcome Guest, Not a member yet? Register   Sign In
Ocular Layout Library version 0.20 Released
#11

[eluser]abmcr[/eluser]
A live example with the code is not downladable? Thank you
#12

[eluser]Beren[/eluser]
Here's a review of something I tried this morning....


Code:
svn export http://dev.ellislab.com/svn/CodeIgniter/trunk CI_trunk

system/application/config/config.php setup with base_url http://localhost:8888/CI_trunk/

Matchbox 0.9.3 installed as per instructions

Ocular 0.21 installed under system/application/modules/Ocular

system/application/config/autoload.php setup with :-
Code:
$autoload['libraries'] = array('Ocular' => 'ocular');
$autoload['helper'] = array('Ocular' => 'ocular');

system/application/views/application.php setup with a $this->ocular->yield() call

system/application/views/welcome/ocular.php created with simple content

system/application/controllers/welcome.php with new function ocular()
Code:
function ocular()
{
  $this->ocular->render();
}

The Result: -
============================================================
An Error Was Encountered

Unable to load the requested file: /welcome/ocular/index.php
============================================================


Full Debug (level 4) log output: -
============================================================
DEBUG - 2008-01-15 11:59:51 --> Config Class Initialized
DEBUG - 2008-01-15 11:59:51 --> Hooks Class Initialized
DEBUG - 2008-01-15 11:59:51 --> URI Class Initialized
DEBUG - 2008-01-15 11:59:51 --> Matchbox Class Initialized
DEBUG - 2008-01-15 11:59:51 --> Router Class Initialized
DEBUG - 2008-01-15 11:59:51 --> Output Class Initialized
DEBUG - 2008-01-15 11:59:51 --> Input Class Initialized
DEBUG - 2008-01-15 11:59:51 --> Global POST and COOKIE data sanitized
DEBUG - 2008-01-15 11:59:51 --> Language Class Initialized
DEBUG - 2008-01-15 11:59:51 --> Loader Class Initialized
DEBUG - 2008-01-15 11:59:51 --> Helpers loaded: ocular
DEBUG - 2008-01-15 11:59:51 --> Config file loaded: config/ocular.php
DEBUG - 2008-01-15 11:59:51 --> Ocular library loaded.
DEBUG - 2008-01-15 11:59:51 --> Controller Class Initialized
DEBUG - 2008-01-15 11:59:51 --> Helpers loaded: inflector
============================================================


I tried this with the standard index.php approach and also with my more usual .htaccess rewrite approach, same result with both.

This is also the same kind of result (though can't swear blind exactly the same) when I tried installing it as a standard library (i.e. traditional installation routine).

All very annoying since I didn't have any of these problems when I setup my first CI app (everything was up and running in a manner of minutes!) which is even now happily serving up content using Ocular! I'm starting to think there might be a conflict with Matchbox library somehow - has anyone had Ocular running successfully with matchbox??

(I hope so because the Matchbox idea is great - I personally would like to see more and more CI third-party code released as matchobx modules for ease of use/conflicting code resolution etc)

Have to get back to work now, but I will try and get some spare moments to have another play with it later in the day if I can.

UPDATE: -

OK, did a bit more probing, problem seems to lie in the get_active_controller() function in ocular_helper.php and what it passes to the yield() function that is building the view path in Ocular.php

Hence the cannot find '/welcome/ocular/index.php' which should be (in this case) '/system/application/views/welcome/ocular.php'

UPDATE 2: -

Yet another quick update so that people who might read this whilst I'm working on it don't spend time doing the same stuff as me!

I have re-written the two function below from ocular_helper.php - this way uses an instance of the router class to return the controller and method names from there rather than determining them from the URI class as was done before. Working so far, but I need to test this with other controller names, sub-directories, modules and re-routed URIs. Will check back in with what I find out.

Code:
function get_active_controller($get_path = FALSE)
{
  $CI =& get_instance();
  $RTR =& load_class('Router');
  if($get_path)
  {
    return $CI->config->item('OCU_layout_dir') . $RTR->fetch_class();
  }
  else
  {
    return $RTR->fetch_class();
  }
}

function get_active_function()
{
  $RTR =& load_class('Router');
  return $RTR->fetch_method();
}

UPDATE 3: -

Small change to get_active_controller() to allow controllers within sub-directories, the code should be pretty self-explanatory but ask if you don't get it.
Code:
function get_active_controller($get_path = FALSE)
{
  $CI =& get_instance();
  $RTR =& load_class('Router');
    
  $controller = $RTR->fetch_class();
    
  if($get_path)
  {
    $controller = $RTR->fetch_directory() . $CI->config->item('OCU_layout_dir') . $controller;
  }
    
  return $controller;
}

I have tried this with
+ standard controllers
+ default controllers
+ re-routed controllers (i.e. routes.php)
+ controllers located in matchbox modules
+ controllers located in sub-directories
All of these appear to be working, at least on my test app here. Obviously this is *very* alpha code, if anyone else has a spare moment or two to try and break it and could report back it would be greatly appreciated. Also, anyone with any other test ideas for me to try and break it, that also would be much appreciated.

Thanks again to kilishan for this great library, hopefully I'll be able to retro-fit my new app in development with Ocular in the not-too-distant future.

Peace all, Beren
#13

[eluser]kilishan[/eluser]
Beren,

Thanks for the testing and the contrib! I had just stumbled across those functions in the router class tonight myself and retrofitted my dev version of Ocular with something very close to what you did. I haven't tested it nearly as thoroughly as you have yet. I was thrilled to find those functions, though, since it cleaned up my code tremendously and took all of my crazy error out of it. I like simple solutions. Smile

About the only thing that I did differently was called the router functions like:

Code:
$CI->uri->router->class;
$CI->uri->router->directory;
$CI->uri->router->method; // For get_active_function()

I'm not a PHP wiz, by any means, but I don't believe there will be any performance/memory hit based on the difference in calling methods. Is that right?
#14

[eluser]Beren[/eluser]
I'm no PHP wiz myself either I'm afraid! I just found the fetch_directory etc methods like you by looking through the codeigniter source - I'm almost 100% sure that the methods you've got in yours are calling exactly the same stuff behinds the scenes, except you're using the router already instantiated so actually yours should be slightly faster since I do the unecessary $RTR =& load_class('Router'); rather than just using $CI->uri->router (which I didn't know I could do!)

Glad to help out - I've actually spent the last couple of evenings working on my own layout library (inspired by Ocular & Rails but going in a slightly different direction, and as a good way to get to know CI) - when I've got the code in a release ready point I'll PM you the code so if there's anything in there that you want to use or see how I've approached something please help yourself.

This CodeIgniter community is really great! As is CI itself! I'm really glad I switched over to CI, deployment & performance on Rails was such a frikkin' joke!
#15

[eluser]jpeffer[/eluser]
I can't seem to find any reference to OCU_layout_dir in the code. I'm guessing that is why changes to the ocular config file are having no affect. I'm using Ocular 0.21 without matchbox. Any help would be appreciated. I would like to place my layouts within a directory called /layouts and possibly sub layout directories within there. If anyone could give me a hand I would appreciate it.
#16

[eluser]kilishan[/eluser]
If you update your code to what's shown just a couple of posts above it should work just fine. I've got a version with those changes sitting on my hard drive at home, but am in the middle of some other changes so can't get a working version posted right now.

Hope that helps.
#17

[eluser]Unknown[/eluser]
The Ocular template library is great, but unless I'm not seeing something it doesn't handle the loading of CSS and Javascript files that are deeply nested. This poses a problem when using a large javascript library alongside CI and Ocular (ex. ExtJS, YUI, etc.). In order to get these libraries and their accompanying themes to function one has to resort to using standard HTML script and style tags, or result to re-wiring the libraries CSS files accordingly. While this isn't a big pain, it does reduce the effectiveness of the asset controller. Again, I could be mistaken--if so, please enlighten.
#18

[eluser]zeroeighteen[/eluser]
One of the things i love about the code is that it totally simplifies the "view within a view" thing for me. It took a while for me to get it working, but it's working now, and i'm slowly getting used to it! Smile

One of the things that i'm having trouble with though, is how to embed pathnames in the css files. For example:

Code:
body {
  background: url(/web_app/assets/images/bg/light_body.gif) repeat-y top center;
}

i'd rather not have to hardcode the url if i don't want to. but if i don't put the slash at the beginning, it will start to look for base_url/modules/ocular/assets/stylesheets/html/layout/images/bg/light_body.gif

is there something i can do about this through the Ocular library? thanks.
#19

[eluser]kilishan[/eluser]
Glad you're getting it to work for you!

The way it's setup by default is to have a "public" directory in the site root. So you'd have:

Code:
root
- public
-- stylesheets
-- images
-- javascripts
- system

If you use the default directory structure, then you can simplify your css to:

Code:
body {
  background: url(/public/images/bg/light_body.gif) repeat-y top center;
}

That's the easiest option, and the one that I've used on a couple of sites that I've done.
#20

[eluser]daweb[/eluser]
I'm trying to use body_id features.

This is my _remap function
Code:
function _remap($method) {

        # ricava il codice annuncio se eventualmente inserito
        $u8 = $this->uri->segment(8);

        # se settato correttamente
        if ( isset($u8) )
        {
            # controlla se il codice effettivamente esiste, cioé è nel DB?
            $check_cod_entry_query = $this->f_entries->check_entry_cod($u8);
            
            if($check_cod_entry_query)
            {
                // assegna il metodo
                $method = 'single_entry';
                // titolo della pagina
                $value_stack['contentTitle'] = $check_cod_entry_query->titolo;
                
                // passa ad ocular i dati che voglio stampare
                $this->ocular->set_view_data('page_title', $value_stack['contentTitle']);
                $this->ocular->set_view_data('body_id', 'page_vendita');
                $this->ocular->set_view_data('data_stack', $value_stack);
                $this->ocular->set_view_data('_viewName', $method);

                  $this->$method();
            }
        }
        
        // assegna il metodo index standard
        $this->$method();
    }

$this->ocular->set_view_data('body_id', 'page_vendita');

but it returns this:

Code:
body id=" id="page_vendita

Where I wrong?!




Theme © iAndrew 2016 - Forum software by © MyBB