Kohana 3.2 was designed to support the HMVC design pattern. The HMVC pattern consists of nested MVC-triads. Yet as far as I can tell, Kohana's cascading file system requires all Models and Controllers to be placed within a top 'classes' directory, and Views into a top 'views' directory. If Model/Controllers are thus separated from Views at the top level of the file system, then how are we supposed to implement nested MVC-triads?
Not sure if you'd want to hack the way that views are processed, but you can extend the Kohana_View class so that set_filename() function will accept any directory that you want.
If you want an auto-loading feature similar to controllers / models, you could implement it yourself.
For example (untested):
public function set_filename($view)
{
// Transform the class name into a path
$file = str_replace('_', '/', strtolower($view));
if ($path = Kohana::find_file('classes', $file))
{
// Store the file path locally
$this->_file = $path;
return $this;
}
throw new View_Exception('The requested view :view could not be found', array(
':view' => $view,
));
}
Yet as far as I can tell, Kohana's cascading file system requires all Models and Controllers to be placed within a top 'classes' directory, and Views into a top 'views' directory.
What you seem to want is a folder structure like Kohana 2, codeigniter and most likely other frameworks, which have dedicated folders for controllers, models, and views. Kohana 3 has a dedicated folder for classes. The way Kohana 3 is built enforces that controllers should have a Controller_ prefix. The Kohana 3 autoloader will look for classes with a Controller_ prefix in the classes/controller folder.
Then Kohana 3 also comes with very basic Model and View classes. The Kohana 3 core does not use the Model class as far as I am aware and it uses the View class only on a few occasions. But the convention to give models the Model_ prefix can be found in Model::factory(), it is not enforced however. You do not have to use them.
The View class looks for templates in de views folder. The (not recommended by Zombor) View_Module by Zombor (one of the devs) also happends to look there. The (redommended by Zombor) KOstache module, again by Zombor, looks for its templates in the templates folder. Both modules let you create View-Model classes for which the convention is to have the View_ prefix so they end up in classes/view. But nothing stops you from creating a View_ class which extends View for every template you put into the views folder and hardcode the path for that View-Model.
Please respect that the classes folder is only for classes.
Related
I'm starting with Express and TypeScript and I would like to know how is the folder structure to define the types in large projects.
For example, in Java projects, models and dto folders are usually created to define their entire structure. Can I follow this same structure in TypeScript or is there a better way?
I have searched and I see that a type.d.ts, type.ts or emun.ts file is usually created, others put users.interface.ts and it groups the entire structure here.
I am using BDD+cucumber+watir framework to automate a website. Folder structure is like this.
Is it possible to maintain all the element Ids(locators)of a page in one file and call it in step definition.
I cannot see the structuring picture but You can either use the PageFactory model structuring for pure POM. If you are used to BDD and want to maintain most part of its features. You can as well store all the element ids to a file called cucumber.yml. You can find the page object gem https://github.com/cheezy/page-object
Create a file called cucumber.yml in your project directory and have all the locators stored in it as like:
LoginPage
emailtextfield: email_text_field_id
You can load this pageelements.yml file using the YAML loader and call this element locator in the stepdefinition like LoginPage[emailtextfield]
Similarly you can categorize this for all the pages, different yml files. This would be a keydriver approach.
I have just started to investigate Microsoft's Entity Framework (EF) with a view to replacing our existing Linq2Sql data access library.
Whilst following some of the sample projects I came across the 'Add Code Generation Item' (context menu on the designer surface), specifically the 'EF 5.x DbContext Generator' template.
This template generates some nice simple (POCO) class objects for the model.
In my overall structure, I would like to extract/move these classes into a different project/assembly so that I can reference them from a generic repository i.e. I want to decouple the application's Data Access Layer from the EF entity data model.
Is this possible, or do I need to manually create a map for each class object (e.g. .ToDomainModel(), .FromDomainModel()).
Apologies if this is a stupid question - in my defence I am new to EF and also still getting to grips with the concept of the Data Driven Domain.
It is possible but you will lose part of the auto-magic. The auto-generated item is a T4 template. If you open it you will find somewhere at the beginning relative path to .edmx file. If you move the template you just need to update the path accordingly to point to the .edmx file you want to use for generation.
The disadvantage is that moving the template elsewhere will break automatic class regeneration when the .edmx file is saved (but I didn't searched for the solution so maybe it is possible to make it work). Because of that you must manually run custom tool (item in .tt file context menu) after each saved change to EDMX file.
When generating my DAL files with SubSonic, I'd like the names of the files to be .gen.cs. The main reason for this is that the files are partial classes, and I would like to add some additional implementation details into another source file for the table called .cs. This is somewhat the standard pattern for generated source files , and I'm wondering if its possible with SubSonic? I'm using SubSonic 2.2.
I thought you might be able to do this by using a set of custom templates, but the CS_ClassTemplate.aspx (or VB_ClassTemplate.aspx) doesn't control the file name of the class.
I don't think this is possible.
As an alternative, you can do what I do. I have a "generated" directory, such as \database\generated and then I put my partial classes at \database\custom. As long as the namespaces of the files in the two different directories match (like .database or whatever), then it works fine. By using two different directories, it's easier to find your custom files without looking at the generated ones.
I'm using SubSonic 2.2 for my DAL. To match the requirement, I need to customize some of classes which generated by SubSonic. For sample:
public partial class Category : ActiveRecord, IActiveRecord, IOtherInterface
Could you please give me some clues. Where I can modify the generated template? Thanks!
Jim is incorrect you can add an Interface via the partial class. I keep one folder with all of the Generated Files and another one with the Altered class files and I am adding an interface to the altered class files and it works just fine.
public partial class ContainerSearch : IContainerSearch
{
}
above is an example from my code I am using now
(edit: see runxc1's post for better answer)
You can modify the templates used to generate the class files to add in your other interface. You can't add an interface to the partial classes. The only trick is that this will add it to all generated classes. You can also just go into your automatically generated classes and add your interface manually after you generate the class files.
SubSonic 2.2 templates are a bit tricker to work with than the 3.0 templates, but it's still really easy to modify the templates.
See below links for info:
how to modify SubSonic 2.1 code generation
http://johnnycoder.com/blog/2008/06/09/custom-templates-with-subsonic/
Your options:
Modify templates used for generation to add in your interface (all classes), or
Modify templates used for generation to add in if/switches to only add interfaces to certain classes that match specific names, etc., or
Edit generated classes to add in your interface (must redo edits after each auto-generation)
After you modified those aspx files. Then you'll just need to update your .config file of your DAL to specify the new path to your customized aspx files and regen as usual.