Zend_Controller tries to execute my stylesheets as controller - zend-framework

I initialize my placeholders for my global layout within the Bootstrap.php as described here.
public function _initPlaceholders()
{
$this->bootstrap('View');
$view = $this->getResource('View');
$view->doctype('XHTML11');
$view->headTitle('Foo Bar Title')
->setSeparator(' :: ');
$view->headMeta()->appendHttpEquiv(
'content-type',
'application/xhtml+xml; charset=UTF-8'
);
$view->headMeta()->appendName('robots', 'index,follow');
$view->headLink()->appendStylesheet('/styles/styles.css', 'screen')
->appendStylesheet('/styles/print.css', 'print');
}
The rendered HTML looks correct.
<title>Foo Bar Title</title>
<link href="/styles/styles.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/styles/print.css" media="print" rel="stylesheet" type="text/css" />
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
<meta name="robots" content="index,follow" />
But the CSS doesn't get loaded correctly because Zend_Controller thinks it's a controller or something. When I try to open the CSS files the following error occurs:
Fatal error: Uncaught exception
'Zend_Controller_Dispatcher_Exception'
with message 'Invalid controller
specified (error)'
Any hints?
[update]
Ok, just added the following line to my .htaccess file and all works as expected now...
RewriteRule
!.(js|ico|txt|gif|jpg|png|css|htc|swf|htm)$
index.php

A typical Zend project layout looks something like this:
.
|-- application
| |-- Bootstrap.php
| |-- configs
| |-- controllers
| |-- forms
| |-- layouts
| |-- models
| `-- views
|-- library
`-- public
|-- images
| `-- favicon.ico
|-- index.php
|-- js
| `-- scripts.js
`-- styles
`-- style.css
Does yours look similar? Specifically, do you have CSS and JavaScript files somewhere under the public folder (and not the application folder)? If so, can you review file permissions?
Also, I recommend reviewing file permissions. If the CSS files aren't readable by the Apache process, then Apache won't be able to serve them.

Related

Unable to access js and style sheet using Play

Here I import from view file:
<script src='javascripts/tic-tac-toe/main.js'></script>
<link rel="stylesheet" type="text/css" href=stylesheets/tic-tac-toe/style.css'>
public folder structure:
[]
routes file:
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
When I try to access the view page I receive following error in firefox console and the files are not loaded :
The resource from
“http://localhost:9000/assets/stylesheets/tic-tac-toe/style.css'” was
blocked due to MIME type (“text/html”) mismatch
(X-Content-Type-Options: nosniff).
How to access js and css resources from view file ?
I can browse directly locally to the files on the browser via the address bar:
http://localhost:9000/assets/javascripts/tic-tac-toe/main.js
http://localhost:9000/assets/stylesheets/tic-tac-toe/style.css
Seems I need to prepend with "assets":
<script src='/assets/javascripts/tic-tac-toe/main.js'></script>
<link rel="stylesheet" type="text/css" href='/assets/stylesheets/tic-tac-toe/style.css'>

Visual Studio Code Advanced Search Wildcard in Files to Include

I am trying to find a line of code to all my files with a specific file name criteria. I am trying to take advantage the Advanced Search of the Visual Studio Code by putting a wildcard in the files to include field of the search. But I wasn't able to achieve that. I tried to use asterisk (*) symbol, but I think the Visual Studio Code does not accept that. So I tried to search the internet and found this solution by using the .+?; however, it still does nothing.
Search Keyword: ICustomMatColumn
files to include: (wildcard)viewmodel.ts
Apparently, the Visual Studio Code supports glob syntax which is really great. To achieve the desired result in the question you just need to do this format
./**/*< partialFileName >
Example
Folder Structure:
|-- app
|-- users
|-- list.ts|html|css|viewmodel
|-- form.ts|html|css|viewmodel
|-- cars
|-- list.ts|html|css|viewmodel
|-- form.ts|html|css|viewmodel
|-- configurator.ts|html|css|viewmodel
|-- app.component.ts|html|css
|-- app.module.ts
|-- user.service.ts
|-- car.service.ts
|-- index.html
|-- main.ts
|-- style.css
Let's Assume that every ViewModel file has this word/code/string ICustomMatColumn
Search Keyword: ICustomMatColumn
Files to Include: ./**/*ViewModel.ts
Search Result:
|-- app
|-- users
|-- list.ts|viewmodel
|-- form.ts|viewmodel
|-- cars
|-- list.ts|viewmodel
|-- form.ts|viewmodel
|-- configurator.ts|viewmodel
It will strictly include only the files with the partialFileName that you entered in the files to include field
So I found that the asterisk (*) works when you put in the files to include field the higher level folder name as the criteria
The format will be higherLevelFolderName*
Example:
Folder Structure:
|-- app
|-- users
|-- list.ts|html|css|viewmodel
|-- form.ts|html|css|viewmodel
|-- cars
|-- list.ts|html|css|viewmodel
|-- form.ts|html|css|viewmodel
|-- configurator.ts|html|css|viewmodel
|-- app.component.ts|html|css
|-- app.module.ts
|-- user.service.ts
|-- car.service.ts
|-- index.html
|-- main.ts
|-- style.css
Let's Assume that every ViewModel file has this word/code/string ICustomMatColumn
Search Keyword: ICustomMatColumn
Files to Include: app*
Search Result:
|-- app
|-- users
|-- list.ts|viewmodel
|-- form.ts|viewmodel
|-- cars
|-- list.ts|viewmodel
|-- form.ts|viewmodel
|-- configurator.ts|viewmodel
But the CONS of this solution is in case your search criteria is present in the other file, it will be included to the search result.

Getting started with a SBT project

I have been given a skeleton SBT project to work on. The directory structure is as follows:
|-- build.sbt
|-- project
| |-- build.properties
| |-- plugins.sbt
| |-- project
| `-- target
|-- README.md
`-- src
|-- main
| `-- scala
| `-- com
| `-- app-name
| |-- domain
| |-- exception
| |-- repository
| `-- util
`-- test
`-- scala
`-- Vagrantfile
The instructions are to create an app entry point which should take a single command line argument and run some logic.
I have managed to get a simple "hello world" sbt project working but I'm new to scala/sbt. Where would I place this entry point and how can I accept a command line argument?
The root folder for source files would be src/main/scala.
Parameters are referenced using the args array within your entry point object.
The entry point is any object under that source tree which extends App. Since this is a hello world example and you're just getting started, I'd drop it right into the root of the sources (src/main/scala/MyApp.scala).
Something like this:
object MyApp extends App {
println(args.length match {
case 0 => "You passed in no arguments!"
case 1 => s"You passed in 1 argument, which was ${args(0)}"
case x => s"You passed in $x arguments! They are: ${args.mkString(",")}"
})
}
To run your app, issue the sbt run command in the project root. To run with parameters, do sbt run "arg1".

autoloading conundrum in zend framework

I am trying to figure out how autoloading function with Zend Framework.
questions:
1 - say I want to add to my application/ folder a folder called x/ containing a class named Foo.php. How do I get it auto-loaded when I do new Foo() from a controller? And then how should I name The class Foo? Is "Foo" alright or should I use the name "Application_X_Foo"?
2 - whats this story with $autoloader->registerNamespace('My_')? I mean where should the classes in the namespace My_ live?
Thanks
1.- For application specific classes you should use Application_Model_Foo as the class name and have it located under "application/models/Foo.php"
2.- If you want to add other namespaces/libraries to your project you could add these under the library/ folder. In the "My_" namespace case you should add it to "library/My" folder.
Here, you can have a look to the directory structure of a basic Zend Framework project:
|-- application
| |-- Bootstrap.php
| |-- configs
| | `-- application.ini
| |-- controllers
| | |-- ErrorController.php
| | `-- IndexController.php
| |-- models
| `-- views
| |-- helpers
| `-- scripts
| |-- error
| | `-- error.phtml
| `-- index
| `-- index.phtml
|-- library
|-- public
| |-- .htaccess
| `-- index.php
`-- tests
|-- application
| `-- bootstrap.php
|-- library
| `-- bootstrap.php
`-- phpunit.xml
By the way i would recomend you to have a look to the Zend Framework Quick Start guide:
http://framework.zend.com/manual/en/learning.quickstart.html

Can't reach the new zend controller/view

I've installed Zend Studio 7.1.1 that contains 1.9 framework.
For the server side, I use easyphp (very similar to wamp)
When I create the project, I obviously obtain this architecture:
MyProject
|-- application
| |-- Bootstrap.php
| |-- configs
| | `-- application.ini
| |-- controllers
| | |-- ErrorController.php
| | `-- IndexController.php
| |-- models
| `-- views
| |-- helpers
| `-- scripts
| |-- error
| | `-- error.phtml
| `-- index
| `-- index.phtml
|-- library
|-- public
| |-- .htaccess
| `-- index.php
`-- tests
|-- application
| `-- bootstrap.php
|-- library
| `-- bootstrap.php
`-- phpunit.xml
To launch the project, I enter:
http://127.0.0.1/MonProjet/public/index.php
But when I create a new controller (TestController.php) and the associated view (application.views/test/index.phtml) and when I enter:
http://127.0.0.1/MonProjet/public/test
the browser returns the error : object not found (404).
although I activated the mod_rewrite
LoadModule rewrite_module modules/mod_rewrite.so
So, how can I set the routing mechanism to reach the new controllers and their views?
Thank you very much,
regards.
It's been quite a while since the question was asked, but nevertheless maybe somebody is still facing the issue. I had the same problem today and it turned out that in apache configuration in httpd.conf the "AllowOverride" was set to "none" and therefore the .htaccess could not be read. Changing it to "All" solved the problem.
Your index.php file has the Autoloader class call which loads all the controller and models automatically.
Along with that you can also add this code in your BootStrap.php file.
protected function _initAutoload()
{
$modeLoader = new Zend_Application_Module_Autoloader(array
('namespace'=>'Application','basePath'=>APPLICATION_PATH ));
return $modeLoader;
}