Im working with Yii, and I'am trying to put my controller into subdirectory.
It works when subdirectory is only 1 folder long :
Controllers / subdirectory / controller.php
But I'am forcing a problem when I want to have a path like this :
Controllers/ subdirectory / subdirectory2 / controller.php
In my urlManager I do everything analogically as it's for single nested way, but i get error :
The system is unable to find the requested action "subdirectory2"
So, it seems like Yii by defoult only understands in path the first subdirecotry as folder and second subdirecotry already considers as action, when i would like be the very last part's of url, so i could also work for longer paths.
Best.
It works in my way. Try to use this in your config file. Also there isn't problems with urlRewrite.
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'test' => 'directory/subdirectory/test/index'
),
),
Related
I'm creating a web app and I need to deploy it as multiple web app instance
Let's say I'm deploying app as
root
|_ app1
|_ app2
|_ app3
Both app2 dan app3 are cloned from app1 via git. After that I do composer install and let them installs..
everything went fine when I log in to app1, but after logging in to app2, My app1 login was logged-out without clear reason. My first verdict was the session colliding, but I don't find any lead changing Laravel session key... So I tried changing the App Key but it doesn't do anything.
Anyone can point me some lead or answer? Thank you
P.S: I access the via subfolder (eg: http://mydomain/app1, http://mydomain/app2, http://mydomain/app3 )
Things I've tried:
changing App Key
changing session.cookie and assign different names
to each site
Edit: changing session.cookie and assign different names
to each site is the correct solution
For security reasons, your session will be terminated, given that they are all stored in the same table.
Basically, you need to have a different config for each of your multisite.
Go to app/bootstrap/start.php
Replace this:
$env = $app->detectEnvironment(array(
'local' => array('homestead'),
));
With this(example):
$env = $app->detectEnvironment([
"app1" => ["app1.mysite.com"],
"app2" => ["app2.mysite.com"]
]);
Then in your app\config folder, create two new folders app1 and app2.
Whatever config files you place in them, will be loaded when the respective websites are visited.
If a config file is not present, the global default will be loaded.
Lastly, no need to have a different app folder for each website, unless you want a clear separation of concerns.
Read more about multisites
Changing session.cookie is the correct solution!
Start creating session.php on config and put different values for cookie for each app
<?php
return [
'cookie' => 'app1'
];
<?php
return [
'cookie' => 'app2'
];
after that CLEAR YOUR BROWSER'S COOKIE! (This is important!)
Without clearing, your last login behaviour will still conflict and the show can't go on.
That's it!
You can have multiple Laravel site which is duplicated from one another on different subfolders.
I am asking this after a couple of hours of searches. I just can't tell what I am missing here. I am trying to set friendly URLs for my Yii application.
My base url is http://www.baby-registry.org/BABYREG/app/
I am trying to change this url http://www.baby-registry.org/BABYREG/app/index.php?r=generalProducts/admin into http://www.baby-registry.org/BABYREG/app/productAdmin
Using this in my main.php config file:
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
),
),
Either with or without rules (tried different rules I found on stackoverflow), this breaks my app altogether, I get the famous notice 'Congratulations! You have successfully created your Yii application.
You may change the content of this page by modifying the following two files:......'
What am I doing wrong?
Does it have anything to do with the fact that I have a base url like (BABYREG/app)?
You will need to post a bit more code, and also what error message (if any) you are getting.
But, a common reason for the URL rewriting not to work in Yii is that the apache module mod_rewrite is off. This apache module is required to use the Yii URL rewriting.
To check whether this module is enabled, in PHP, use apache_get_modules(); This will return an array of enabled apache modules. So a simple way to check if mode_rewrite is enabled is:
if (in_array('mod_rewrite', apache_get_modules())){
// mod_rewrite is enabled
}
If it is not enabled, ask you hosting company to enable it for you. If you are working on your local host (with WAMP), simply enable it by clicking it under the apache menu - modules in the WAMP icon on the system tray
I just spent way too long with my array arguments reversed. Here's my first successful rewrite:
Link in app:
<a href='<?php echo Yii::app()->createUrl("home"); ?>'>Rewriting test</a>
PHP config:
'rules'=>array('successfully/rewritten' => 'home');
Note that it's desired url and then existing url. Backwards, in my head - I'd reckon it's "rewrite this, to this". Instead, it's "this is the rewrite for this." ^_^
I am trying to use send_file to stream 1000 pictures on the browser, and simulate video streaming. I currently run my server (locally) using thin, and I have this in my controller:
send_file 'bg.jpg', :type => 'image/jpg', :disposition => 'inline'
I did not find any tutorials that explain send file, and I heard that I have to use ngnix to make it work. Any help streaming the pictures?
The page returns "Cannot read file bg.jpg", but the file is there, in the assets/images/ folder
Try
send_file 'assets/images/bg.jpg', :type => 'image/jpg', :disposition => 'inline'
Since send_file is not an assets method you will need to supply the full path to it.
I am new to rails and want to do a simple routing to root operation. My file path is app/views/slots/index.html.erb. When I go in my routes.rb file and see:
You can have the root of your site routed with "root"
just remember to delete public/index.html.
root :to => 'welcome#index'
I change the 'welcome#index' to "slots#index', I get this error from localhost:3000:
No route matches [GET] "/"
In the terminal, I use ctrl c to exit server and $ rails server to restart and still get the error. I watched my instructor do the same exact simple steps yet I get this error. Anyone know what I did wrong?
Edit : my bad, indeed the error is not corresponding to the solution I described below.
It seems you didn't create the slots controller.
You have to create a controller to display files. app/views/slots/index.html.erb is just a view, corresponding to an action of a controller.
So create the file app/controller/slots.rb
class SlotsController < ApplicationController
def index
end
end
You can do this faster with generator. In your terminal, cd to your application path and then
rails generate controller Slots index
To learn Rails I recommend you some reading here : http://guides.rubyonrails.org/getting_started.html
I am trying to use rack offline in rials to make my webpage available offline. By default rack offline takes all files from the public folder into the cache manifest. In which file should I make changes so that it will take the add the file that I want into the cache manifest. I want to include the file in my views folder.
You need to add it to your routes.rb file. Here is my routes.rb file with a customized manifest. This will give you the index and the new routes as well as all of the html files in your public root (*.html) and every file in a sub-folder to public (*/*.*). You can slice and dice that however you need it for stuff in the public folder.
I don't know how to get the database specific routes like show and edit while offline. I would imagine Javascript is needed. Check out Railscast episode 248 for some ideas for integrating JS
OfflineConfirm::Application.routes.draw do
#match '/application.manifest' => Rails::Offline
resources :contacts
offline = Rack::Offline.configure do
cache ["contacts/new", "contacts"]
public_path = Rails.root.join("public")
Dir[public_path.join("*.html"),
public_path.join("*/*.*")].each do |file|
p = Pathname.new(file)
cache p.relative_path_from(public_path)
end
network "/"
end
match '/application.manifest' => offline
end
The routes file above will produce the following application.manifest
CACHE MANIFEST
# 700ae3e3002382cb98b93c299d7b7bda151183b4703ef65d4c46b0ecf9c46093
contacts/new
contacts
404.html
422.html
500.html
index.html
images/rails.png
javascripts/application.js
javascripts/jquery.js
javascripts/jquery.min.js
javascripts/rails.js
stylesheets/scaffold.css
NETWORK:
/
None of the files in your views folder are available without a server. You want to make a route available in the cache manifest? For instance "/about", which corresponds to a "views/about.haml" file for instance?
Add this to your config:
offline = Rack::Offline.configure do
cache "about" # or whatever your route is
public_path = Rails.public_path
Dir[public_path.join("javascripts/*.js")].each do |file|
cache file.relative_path_from(public_path)
end
end